Answer the question
In order to leave comments, you need to log in
Why is copy constructor not available?
Language: C++
When I try to compile the program below, I get an error stating that no copy constructor is available. Please tell me what is the problem?
Error text:
Error 1 error C2558: class "Rock": No copy constructors available or copy constructor declared as "explicit" c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 593 1 upr_14_26
#include <iostream>
#include <vector>
using namespace std;
class Rock {
public:
Rock(void) { cout << "Rock()" << endl; }
Rock(Rock&) { cout << "Rock(Rock&)" << endl; }
void operator=(Rock& rob) {
cout << "operator=(Rock& rob)" << endl;
}
~Rock(void) { cout << "~Rock()" << endl; }
};
int main(void)
{
vector<Rock> vec;
Rock arr[3];
for (int i = 0; i < 3; i++)
vec.push_back(arr[i]);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question