我有:
VirtualClass : public QObject
{
public:
int m_number;
}
DerivedClass : public VirtualClass
{
public:
DerivedClass(int number) : m_number(number) {};
int m_number;
// some content goes here..
}
客户端代码:
f(VirtualClass* instance)
{
std::cout << instance->m_number;
}
DerivedClass der(100);
我想f(der)
返回与 DerivedClass 相关的 m_number,但 *我得到了 VirtualClass* 的 m_number。我做错了什么?!