0
我創建了幾乎完全相同的類和派生類。 唯一的區別是派生類有2個不同的函數和3個額外的變量。我想調用的函數從B級到使用繼承的功能,但與B類的PrivFunctions而是調用時,該函數使用從基類中調用使用派生類的成員函數的函數
class A
{
protected:
double x,y,z;
Function() {
*do something using the member variables of class A and the member functions of class A* }
private:
double PrivFunction() {
*take in member variables from A and return a certain value* }
double PrivFunction2() {
*take in member variables from A and return a certain value* }
class B : public A
{
private:
double a,b,c;
double PrivFunction() {
*take in member variables from A,B and return a certain value* }
double PrivFunction2() {
*take in member variables from A,B and return a certain value* }
main() {
B classb();
B.Function()
}
我想過自己的類,A類的PrivFunctions在Function()中添加私有函數的地址,但似乎太過牽強。我覺得我錯過了簡單的東西,但我不知道如何做到這一點整齊
我認爲你正在尋找['virtual'成員函數(http://en.cppreference.com/w/cpp/language/virtual) 。 –