开发者

abstract declarator Node* used as declaration

I am using an abstract class SetOfInt; where a Btree baseclass inherits from. The declaration of the virtual function find gives me a compiler error and I cannot figure out why?

This is the exact error:

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'

Any help would be highly appreciated!

/*  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 */ };


The return types should go after the virtual keyword.

i.e.

virtual void add(int x);

instead of

void virtual add(int x);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜