为什么不允许虚方法返回 void 指针

Why the void pointer is not allowed be returned by virtual methods?

本文关键字:void 指针 返回 方法 不允许 为什么      更新时间:2023-10-16

最近我尝试编译这个类

class Foo{
public: void virtual doSomething()=0;
void* virtual getBar()=0;//error
protected: Foo(){};
};

但是编译器不编译,并说"ISO C++ forbids declaration of ‘getBar’ with no type [-fpermissive]"编译器:gnu 4.8

你弄错了语法。你需要

virtual void* getBar()=0;