【发布时间】:2013-11-30 05:07:07
【问题描述】:
我的头文件是这样的:
class A
{
public:
A();
A(A const & other);
private:
class B
{
public:
B * child;
int x;
int y;
void copy( B * other);
};
B * root;
void copy( B * other);
};
虽然我的 cpp 文件是:
A::A()
{
root = NULL;
}
A::A(A const & other)
{
if (other.root == NULL)
{
root = NULL;
return;
}
copy(other.root);
}
void A::copy( B * other)
{
if (other == NULL)
return;
this->x = other->x;
this->y = other->y;
this->child->copy(other->child);
}
但是,当我编译我的代码时,我得到了错误 - 'class A has no member named x'
我猜这是因为“x”是私有的 B 类的成员。是否可以在不改变头文件结构的情况下制作复制构造函数。
【问题讨论】:
-
in
void A::copy(B* other),this->x表示A::x并且A没有x或y
标签: c++ copy-constructor