为什么不允许虚方法返回 void 指针
Why the void pointer is not allowed be returned by virtual methods?
最近我尝试编译这个类
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;
相关文章:
- 如何在 C++ 中将 void 函数传递给 void 指针
- 将通用引用强制转换为可调用的 void 指针,反之亦然
- C++为 void 指针分配一个字符串
- 为什么在将 void 指针转换为整数指针时出现分段错误
- 取消引用 void 指针以将值分配给结构
- C 与 C++,处理 void** 指针
- 除了调用全局删除运算符之外,删除一个void指针还能做什么呢
- 用非零值初始化void指针的正确(或最安全)方法
- 将 void 指针分配给另一个 void 指针
- c ++ 我是否需要手动删除指向另一个具体类型的 void* 指针?
- 如何将 std::string 作为构造函数参数传递,并将其保存的 C 字符串存储在 void 指针中?
- 如何将 std::string 赋回作为 <char>void* 指针传递的 std::vector.data()?
- 将指针传递到结构,与传递 void 指针并强制转换为结构
- 如何在void*指针下检查运行时类型(允许简单类型,没有基类)?
- 用于初始化结构的 void 指针强制转换
- 使用 void 指针:void **ptr.. 如何修改共享内存的值?
- 访问由 void 指针引用的结构的成员
- 你不能在 void 指针上使用指针算法,那么 void 指针数组是如何工作的呢?
- 如何警告 C 中 void 指针上的参数不兼容的类型
- 指向类模板方法的 void 指针的向量