class CColor
{
public:
unsigned int color;
CColor( const CColor& c)
{
color = c.color;
}
};
class A
{
public:
CColor color;
A(CColor nc)
: color( CColor(nc) )
{
}
};
C++ Constructor initializer lists
Quote:Original post by Endar
Does this actually invoke the CColor's copy constructor twice? Should it be simply "color( nc )"?
Correct.
Actually, I think it copies it 3 times? Once to pass the argument because it isn't by reference . . .
Quote:Original post by Squirm
Actually, I think it copies it 3 times? Once to pass the argument because it isn't by reference . . .
depends on where you start counting ;) I just counted the initializer list, if you also count the call to A's ctor then you get three indeed.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement