Vectors and custom classes
I had an inkling the following code wouldn't work before I compiled it but I was vindicated and I don't feel any good.
Code:
class A
{
private:
int i;
public:
A(){}
A(A& a){i = a.get_i();}
~A(){}
void set_i(int j){i = j;}
int get_i(){return i;}
};
int main()
{
A b;
vector<A> bb;
for(int i = 0; i < 10; i++)
bb.push_back(b);
bb[0].set_i(3);
bb[1].set_i(4);
...
}
Well, the error message I get is the following:
Quote:
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(810): error C2558: class 'A' : no copy constructor available or copy constructor is declared 'explicit'
Aren't vectors supposed to work with all sorts of classes and types?
And how do you make a copy construtor that works with a vector?