是否有可能从联盟中获得以下行为?
class A : public Base //Base is an abstract base class.
{
public:
A( int );
virtual void foo() //A virtual function from Base.
{
//I don't want to have to specify if it's oneOption or twoOption.
// I would like it to just call whichever one's is defined in mData.
mData.foo();
}
private:
union B
{
C oneOption; //A class which inherits from Base.
D twoOption; //Another class which inherits from Base.
} mData;
};
基本上,我想要一个包含派生类联合的类。然后我想根据我的 Union 来实现所有的虚函数基类。
如果它太令人困惑,我可以尝试重新措辞。
谢谢