2014-04-26 15 views
22

tôi nhận được các lỗi sau đây:Bắt lỗi: ISO C++ cấm tuyên bố không có loại

ISO C++ forbids declaration of ttTreeInsert with no type

ISO C++ forbids declaration of ttTreeDelete with no type

ISO C++ forbids declaration of ttTreePrint with no type

prototype for int ttTree::ttTreePrint() does not match any in class ttTree

candidate is: void ttTree::ttTreePrint()

Đây là tập tin tiêu đề của tôi:

#ifndef ttTree_h 
#define ttTree_h 

class ttTree 
{ 
public: 
    ttTree(void); 
    int ttTreeInsert(int value); 
    int ttTreeDelete(int value); 
    void ttTreePrint(void); 

}; 

#endif 

Đây là tập tin cpp của tôi:

#include "ttTree.h" 

ttTree::ttTree(void) 
{ 

} 

ttTree::ttTreeInsert(int value) 
{ 
} 

ttTree::ttTreeDelete(int value) 
{ 
} 

ttTree::ttTreePrint(void) 
{ 
} 

Mọi người có thể chỉ ra nguyên nhân gây ra những lỗi này không? Cảm ơn bạn!

Trả lời

39

Bạn quên các loại trở lại trong định nghĩa hàm thành viên của bạn:

int ttTree::ttTreeInsert(int value) { ... } 
^^^    

và vân vân.

6

khai của bạn là int ttTreeInsert(int value);

Tuy nhiên, định nghĩa của bạn/thực hiện là

ttTree::ttTreeInsert(int value) 
{ 
} 

Chú ý rằng sự trở lại loại int là mất tích trong việc thực hiện. Thay vào đó, phải là

int ttTree::ttTreeInsert(int value) 
{ 
    return 1; // or some valid int 
} 
Các vấn đề liên quan