【发布时间】:2013-05-06 16:11:01
【问题描述】:
我认为我对对象以及扩展对象时会发生什么感到有点困惑。
我的目标是通过扩展 A() 来创建 B(),以便获得 A() 的所有功能等,但让 B() 在创建自身等方面完全自给自足
B(),当从某个地方实例化时,最终会设置它的颜色、调整大小、设置它的位置等,以便我可以执行以下操作:
B::B *b = new B:B(something in);
this -> addChild(b, 1);
因此,当 this->addChild() 之后,它会添加并且事情按照我在 B() 中设置的方式工作
对比:
B::B *b = new B:B(something in);
b->setPosition();
b->setColor();
...
this -> addChild(b, 1);
是否在封装和继承?
更新:所以我认为让我感到困惑的是,如果:
class A : public Z {
}
class b : public Z {
}
在 A 中:
B::B *b = new B::B()
this-> addChild(b,1)
这不应该工作吗?
【问题讨论】:
-
代码中的 A 在哪里? (这个?)
标签: c++ object inheritance instantiation encapsulation