拷贝构造函数

class CA
{
public:
CA()
{
_i = 7;
}
CA(const CA& ca)
{
this->_i = ca._i;
}
private:
int _i;
};
int _tmain(int argc, _TCHAR* argv[])
{
CA a;
CA b = a;
return 0;
}
CA b = a; 会调用拷贝构造函数;
若改为:
CA b;
b = a; 不会调用拷贝构造函数,但如果存在会调用以下函数:
CA& operator = (const CA& ca)
{
this->_i = ca._i;
return *this;
}
发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>