【发布时间】:2014-05-23 10:43:59
【问题描述】:
我有一个关于 C++ 派生类中“this”点的问题。
class A
{
int a;
public:
void funca() { cout << this << endl; }
};
class B
{
int b;
public:
void funcb() { cout << this << endl; }
};
class Derived : public A, public B {};
int main() {
Derived d;
d.funca();
d.funcb(); // prints 4bytes more than the above.
}
在这种情况下,如何在派生类中解释基类中的“this”? 这是派生类的this还是基类的this? 从输出中,我认为这指向了使用它的类对象。我说的对吗?
【问题讨论】:
标签: c++ inheritance this derived