Click to See Complete Forum and Search --> : copy constructor question


rachelsing
September 12th, 2002, 10:26 AM
I get an error when compiling the follow code:
class SomeType
{
public:
SomeType() { };
SomeType(SomeType& x) {};

};

std::vector<SomeType> array;
SomeType sometype1;
array.push_back(sometype1);


I get:
error C2558: class 'SomeType' : no copy constructor available

But I defined the copy constructor. If I comment out that line and uses the default copy constructor the code compiles.

jfaust
September 12th, 2002, 10:37 AM
Try passing a "const SomeType&".

If the default is sufficient, don't bother adding it at all.

Jeff

rachelsing
September 12th, 2002, 10:41 AM
Thanks that worked.