获取错误:ISO C++ 禁止无类型声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23314409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting error: ISO C++ forbids declaration of with no type
提问by user2264035
I'm getting the following errors:
我收到以下错误:
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()
ISO C++ 禁止声明没有类型的 ttTreeInsert
ISO C++ 禁止声明没有类型的 ttTreeDelete
ISO C++ 禁止声明没有类型的 ttTreePrint
int ttTree::ttTreePrint() 的原型与类 ttTree 中的任何内容都不匹配
候选是:void ttTree::ttTreePrint()
Here is my header file:
这是我的头文件:
#ifndef ttTree_h
#define ttTree_h
class ttTree
{
public:
ttTree(void);
int ttTreeInsert(int value);
int ttTreeDelete(int value);
void ttTreePrint(void);
};
#endif
Here is my .cpp file:
这是我的 .cpp 文件:
#include "ttTree.h"
ttTree::ttTree(void)
{
}
ttTree::ttTreeInsert(int value)
{
}
ttTree::ttTreeDelete(int value)
{
}
ttTree::ttTreePrint(void)
{
}
Can anyone point out what is causing these errors? Thank you!
谁能指出导致这些错误的原因?谢谢!
回答by juanchopanza
You forgot the return types in your member function definitions:
您忘记了成员函数定义中的返回类型:
int ttTree::ttTreeInsert(int value) { ... }
^^^
and so on.
等等。
回答by ap-osd
Your declaration is int ttTreeInsert(int value);
你的声明是 int ttTreeInsert(int value);
However, your definition/implementation is
但是,您的定义/实现是
ttTree::ttTreeInsert(int value)
{
}
Notice that the return type int
is missing in the implementation. Instead it should be
请注意,int
实现中缺少返回类型。相反应该是
int ttTree::ttTreeInsert(int value)
{
return 1; // or some valid int
}