2011-06-27 124 views
2

我正在使用抽象類SetOfInt; Btree基類繼承自哪裏。虛函數查找的聲明給了我一個編譯器錯誤,我無法弄清楚爲什麼?抽象聲明節點*用作聲明

這是確切的錯誤:

SetOfInt.h:21: error: expected unqualified-id before 'virtual'
SetOfInt.h:21: error: abstract declarator 'Node*' used as declaration
SetOfInt.h:21: error: expected ';' before 'virtual'
SetOfInt.h:30: error: expected unqualified-id before 'virtual'
SetOfInt.h:30: error: abstract declarator 'Node*' used as declaration
SetOfInt.h:30: error: expected ';' before 'virtual'

任何幫助,將不勝感激!

/* 1 */ #include <cstdlib> 
/* 2 */ #include <iostream> 
/* 3 */ 
/* 4 */ using namespace std; 
/* 5 */ 
/* 6 */ class Node 
/* 7 */ { 
/* 8 */ public: 
/* 9 */  Node (int x); 
/* 10 */  int m_data; 
/* 11 */  Node *m_left; 
/* 12 */  Node *m_right; 
/* 13 */ }; 
/* 14 */ 
/* 15 */ class SetOfInt 
/* 16 */ { 
/* 17 */ public: 
/* 18 */  void virtual add(int x)=0; 
/* 19 */  bool virtual test(int x)=0; 
/* 20 */  bool virtual remove(int x)=0; 
/* 21 */  Node* virtual find(int x)=0; 
/* 22 */ }; 
/* 23 */ 
/* 24 */ class Btree : public SetOfInt 
/* 25 */ { 
/* 26 */ public: 
/* 27 */  void virtual add(int x); 
/* 28 */  bool virtual test(int x); 
/* 29 */  bool virtual remove(int x); 
/* 30 */  Node* virtual find(int x); 
/* 31 */  Node *m_root; 
/* 32 */ }; 
+0

'虛擬節點*'? –

回答

4

返回類型應該跟在virtual關鍵字之後。

virtual void add(int x); 

代替

void virtual add(int x); 
+0

謝謝,那就是訣竅! – liegebeest