0

当我尝试构建头文件、类和构造函数时,我不断收到错误。Dev C++ 给了我一堆错误,我不知道如何解决它们。我已将错误作为注释包含在代码中:

测试.cpp

#include <iostream>
#include <conio.h>
#include "Header2.h"

int main()
{ //ERROR: new types may not be defined in a return type; extraneous `int' ignored;
  //       `main' must return `int' 
    Object Thing(1);
    std::cout << "The truth value is: " Thing.getValue() << std::flush << "/n";
  //ERROR: ISO C++ forbids declaration of `getValue' with no type 

    getch();
    return 0;
}

Header2.h

#ifndef Object_H_
#define Object_H_

class Object
{
 public:
        Object(int a);

        int getValue();
 private:
         int truthValue;
}

#endif // Object_H_

Header2.cpp

#include <iostream>
#include "Header2.h"

Object::Object(int a)
{ //ERROR: new types may not be defined in a return type; 
  //       return type specification for constructor invalid 
 if (a != 0 || a !=1)
 {
   std::cout << "Improper truth value." << std::flush;
 } else 
 {
  truthValue = a;
  }
}

Object::getValue()
{ //Error: ISO C++ forbids declaration of `getValue' with no type 
 return truthValue;
}

我不明白。我究竟做错了什么?

4

1 回答 1

5

你需要;在你的声明的末尾Object

class Object
{
    ....
};
于 2013-11-10T22:01:58.750 回答