【问题标题】:Explicit type is missing (int assumed)缺少显式类型(假定为 int)
【发布时间】:2013-11-22 17:12:27
【问题描述】:

我不明白我做错了什么。这是一个非常简单的程序,我用来练习使用头文件、类和构造函数。它说我没有丢失 Header2.cpp 中函数 getValue() 的返回类型。我不知道如何解决它。有什么想法吗?

Test.cpp

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

int main()
{
    Thing Implement(1);
    std::cout << "The truth value is: " << Implement.getValue() << std::flush << "/n";

    _getch();
    return 0;
}

Header2.h

#ifndef Object_H_
#define Object_H_

class Thing
{
public:
    Thing(int a);

int getValue();
private:
int truthValue;
};

#endif // Object_H_

Header2.cpp

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

Thing::Thing(int a)
{
if (a != 0 || a != 1)
{
    std::cout << "Improper truth value." << std::flush;
}
else
{
    truthValue = a;
}
};

Thing::getValue()
{
return truthValue;
};

【问题讨论】:

  • 它是“Header.h”还是“Header2.h”?
  • Header2.h 和 Header2.cpp。对于那个很抱歉。我将编辑主要帖子以解决此问题。

标签: c++ class constructor header


【解决方案1】:

你缺少一个 int

int Thing::getValue()
{
return truthValue;
};

【讨论】:

    【解决方案2】:
    Thing::getValue()
    {
    return truthValue;
    };
    

    应该是:

    int Thing::getValue()
    {
    return truthValue;
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-26
      • 2015-05-02
      • 2016-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      • 1970-01-01
      相关资源
      最近更新 更多