I do not provide any custom constructors for my class, all I did was disable the copy constructor:
private:
MyClass(const MyClass& other) = delete;
Now when I try to instantiate this class on the stack
MyClass myInstance;
I get a compilation error as follows:
main.cpp:16:16: error: no matching function for call to ‘MyClass::MyClass()’
As if I accidentally disabled the default constructor? Or perhaps the copy constructor is typed there, I just don't see how.
Here is an example
class MyClass {
public:
int someField;
private:
MyClass(const MyClass& other) = delete;
MyClass& operator=(MyClass other) = delete;
};
And mistake
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"proj/main.d" -MT"pitch/main.o" -o "proj/main.o" "../proj/main.cpp"
../proj/main.cpp: In function ‘int main()’:
../proj/main.cpp:17:10: error: no matching function for call to ‘MyClass::MyClass()’
MyClass ins;
source
share