A
A
AF2014-08-02 17:37:07
Programming
AF, 2014-08-02 17:37:07

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

Program text:
#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

1 answer(s)
J
jcmvbkbc, 2014-08-02
@TiPo

Obviously the vector wants a copy constructor that accepts a const Rock&.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question