class A
{
public:
int i;
A(int ii) { i = ii; }
A(const A& a) { i = a.i; i++; }
A& operator=(const A& a) { this->i = a.i; i--; return *this}
};
int main(void)
{
A a(4);
A b = a; //this calls copy constructor not assignment operator
//A b(4); b=a; this calls assignment operator
cout << b.i << endl;//the result is 5
return 0;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment