我正在为个人项目中的框架的各个组件设置一个接口,并且我突然想到了一些我认为可能对接口有用的东西。我的问题是,这是否是可以或不可以:是否可以在类中创建虚拟类声明?
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++抛出我一堆语法错误,那么,有没有办法做到这一点,我只是不写对吗?
你或许可以做到这一点使用*抽象类* – 2012-04-20 06:16:35
听起来像一个XY问题什么是你真正的问题,因为不管它是什么,上面的代码是不是解决 – MSalters 2012-04-20 07:12:58