获取错误:ISO C++禁止无类型的声明

Getting error: ISO C++ forbids declaration of with no type

本文关键字:类型 声明 禁止 C++ 取错误 ISO 获取      更新时间:2023-10-16

我得到以下错误:

ISO C++禁止声明没有类型的ttTreeInsert

ISO C++禁止声明没有类型的ttTreeDelete

ISO C++禁止声明没有类型的ttTreePrint

int ttTree::ttTreePrint()的原型与类ttTree 中的任何原型都不匹配

候选为:void ttTree::ttTreePrint()

这是我的头文件:

#ifndef ttTree_h
#define ttTree_h
class ttTree 
{
public:
  ttTree(void);
  int ttTreeInsert(int value);
  int ttTreeDelete(int value);
  void ttTreePrint(void);
  
};
#endif

这是我的.cpp文件:

#include "ttTree.h"
ttTree::ttTree(void)
{
  
}
ttTree::ttTreeInsert(int value)
{
}
ttTree::ttTreeDelete(int value)
{
}
ttTree::ttTreePrint(void)
{
}

有人能指出这些错误的原因吗?非常感谢。

您忘记了成员函数定义中的返回类型:

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

等等。

您的声明是int ttTreeInsert(int value);

但是,您的定义/实现是

ttTree::ttTreeInsert(int value)
{
}

请注意,实现中缺少返回类型int。相反,它应该是

int ttTree::ttTreeInsert(int value)
{
    return 1; // or some valid int
}