"类形状"没有名为"info"的成员,但添加一个也不起作用
‘class shape’ has no member named ‘info’ but adding one doesn't work either
我正在尝试获取一些代码来编译(此代码(,但是当我注释掉第 25 行时:virtual void info()=0;
它不编译:
shape.cpp: In function ‘int main()’:
shape.cpp:345:11: error: ‘class shape’ has no member named ‘info’
svec[0]->info();
但是保留第 25 行会给出一个关于纯虚函数的很长的错误......
shape.cpp:77:15: error: cannot declare parameter ‘squ’ to be of abstract type ‘square’
cube(square squ):
^
shape.cpp:30:7: note: because the following virtual functions are pure within ‘square’:
class square : public shape {
^
shape.cpp:25:16: note: virtual void shape::info()
virtual void info()=0;
^
shape.cpp:167:20: error: cannot declare parameter ‘rec’ to be of abstract type ‘rectangle’
cuboid(rectangle rec, double d):
^
shape.cpp:110:7: note: because the following virtual functions are pure within ‘rectangle’:
class rectangle : public shape {
^
shape.cpp:25:16: note: virtual void shape::info()
virtual void info()=0;
等等...
谁能告诉我我做错了什么?谢谢。
该函数在派生类中声明const
,但不在基类中声明。这意味着派生类不会重写函数;它们只是声明一个具有相同名称的不同函数。
在基类中添加const
,或在派生类中删除它。
相关文章:
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 将小部件添加到布局后,QStylesheet 不起作用
- 双链接列表添加元素不起作用,不知何故它总是保持为空
- 我试图键入一个函数来在单链表的末尾添加一个节点,但不起作用
- 将子类添加到基类向量C++不起作用
- 将类添加到矢量不起作用
- 添加到私人变量不起作用
- 在 cmake 中添加子目录不起作用
- 添加项目后C find()函数不起作用
- 使用AddFontresourceex添加的字体在GDI 中不起作用
- 将布局从一个类添加到另一类不起作用
- 套接字不起作用,当添加 opencv libriary
- 当通过引用传递时,通过传递链表在第n个位置添加元素不起作用
- 添加 QSound 后应用程序部署不起作用
- Android.mk 添加LOCAL_CPPFLAGS不起作用
- 向注册表添加新项不起作用
- 将多个整数添加到一个向量索引? 'Cout'不起作用
- C++添加不起作用
- 添加 -lrt 时跟踪编译器错误"undefined reference"不起作用
- 库达上的原子添加不起作用..