簡體   English   中英

'class shape'沒有名為'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 ,或在派生類中刪除它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM