0
我試圖訪問基類的成員變量.. 如何做到這一點?如何在C++中訪問基類的成員變量?
=====================以下是ClassA(父類)================== =========
class ClassA
{
public:
int member_Var; // Parent member_var
ClassA();
~ClassA();
void ClassA::initProcess();
};
ClassA::ClassA(){}
ClassA::~ClassA(){}
void ClassA::initProcess()
{
member_Var = 20;
}
=================以下是ClassA的子類的ClassB =========== =====
class ClassB : public ClassA
{
public:
int member_Var; // Subclass member_var
ClassB();
~ClassB();
void ClassB::initProcess();
};
ClassB::ClassB(){}
ClassB::~ClassB(){}
void ClassB::initProcess()
{
ClassA->member_Var = 10; // Is this correct? or How to access base instances's member variable?
member_var = 100;
}
謝謝timrau。它運作良好。 –