The copy constructor isn't called. Why?
Here is the code.
When getCircle() returns, it should call the copy constructor and generate a temporary object, right?Code:#include<iostream> using namespace std; class Circle { private: int x,y; int radius; public: Circle(); Circle(const Circle &); }; Circle getCircle(); int main() { Circle c; c = getCircle(); cin.get(); return 0; } Circle::Circle() { x = y = radius = 30; } Circle::Circle(const Circle &c) { cout << "copy constuctor!" << endl; x=c.x; y=c.y; radius = c.radius; } Circle getCircle() { Circle c; return c; }
But it comes out that the copy constructor is not call cause I cannot find `copy constuctor!' in the output.



LinkBack URL
About LinkBacks


