#include <iostream>
#include <vector>
using namespace std;
class CTemp
{
public:
int a;
CTemp(CTemp &rhs)
{cout << "Copy cons" << endl;}
CTemp()
{cout << "cons" << endl;}
};
void function(vector<CTemp> &vec)
{
CTemp temp1;
vec.push_back(temp1);
return;
}
int main()
{
cout << "in main" << endl;
};
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(810): error C2558: class 'CTemp' : no copy constructor available or copy constructor is declared 'explicit'
If I comment out the copy contructor then it compiles. So how can I use vectors of Classes that have custom copy constructers. I must be missing something fundemental here.
Graham.
copy constructor and vectors
I get a compile error with this code
The copy contructor is supposed to take a const reference. So change it to this:
CTemp( const CTemp &rhs )
{
blah
}
See this for more info: http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html
EDIT: meh....
-SirKnight
CTemp( const CTemp &rhs )
{
blah
}
See this for more info: http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html
EDIT: meh....
-SirKnight
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement