我正在为个人项目中框架的各种组件设置一个接口,我突然想到了一些我认为可能对接口有用的东西。我的问题是这是否可能:
class a
{
public:
virtual class test = 0;
};
class b : public a
{
public:
class test
{
public:
int imember;
};
};
class c : public a
{
public:
class test
{
public:
char cmember; // just a different version of the class. within this class
};
};
有点声明一个虚拟类或纯虚拟类,需要在派生对象中定义,这样你就可以做这样的事情:
int main()
{
a * meh = new b();
a * teh = new c();
/* these would be two different objects, but have the same name, and still be able
to be referred to by an interface pointer in the same way.*/
meh::test object1;
teh::test object2;
delete meh;
delete teh;
return 0;
}
msvc++ 给我抛出了一堆语法错误,那么有没有办法做到这一点,而我只是写得不对?