Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ‘;类形状’;没有名为‘的成员;信息’;但增加一个并不意味着';也不行_C++_Oop_Inheritance_Polymorphism_Abstract Base Class - Fatal编程技术网

C++ ‘;类形状’;没有名为‘的成员;信息’;但增加一个并不意味着';也不行

C++ ‘;类形状’;没有名为‘的成员;信息’;但增加一个并不意味着';也不行,c++,oop,inheritance,polymorphism,abstract-base-class,C++,Oop,Inheritance,Polymorphism,Abstract Base Class,我试图编译一些代码(),但当我注释掉第25行时: virtualvoid 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 ‘

我试图编译一些代码(),但当我注释掉第25行时:
virtualvoid 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
,要么在派生类中删除它。

谢谢你,迈克,这解决了问题!我会尽快接受你的答复