-4
我有一個類test_d
公開繼承類test_b
。類test_d
具有函數getValues()
,我需要使用類test_b
的對象調用。我嘗試使用dynamic_cast
和reinterpret_cast
,但它沒有奏效。有沒有其他方法可以做到這一點?使用派生函數從基類
class test_b {
// this is the base class
};
class test_d : public test_b {
// this is the derived class
public int getValues() const; // this is the function I need to use.
};
test_b* objB = new test_d;
dynamic_cast<test_d*>(objB)->getValues(); // this is what I am doing.
這聽起來像一個嚴重有瑕疵的設計... –
你可以詳細說明「它沒有工作」? 'dynamic_cast'看起來應該起作用(忽略基類不應該知道其派生類型的事實)。 – juanchopanza
看起來像是一些破解的OOP – alex