首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少显式类型(假定为int)

缺少显式类型(假定为int)
EN

Stack Overflow用户
提问于 2013-11-11 08:53:15
回答 2查看 19K关注 0票数 1

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

Test.cpp

代码语言:javascript
复制
#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

代码语言:javascript
复制
#ifndef Object_H_
#define Object_H_

class Thing
{
public:
    Thing(int a);

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

#endif // Object_H_

Header2.cpp

代码语言:javascript
复制
#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;
};
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-11 08:57:37

您缺少一个int

代码语言:javascript
复制
int Thing::getValue()
{
return truthValue;
};
票数 7
EN

Stack Overflow用户

发布于 2013-11-11 08:56:58

代码语言:javascript
复制
Thing::getValue()
{
return truthValue;
};

应该是:

代码语言:javascript
复制
int Thing::getValue()
{
return truthValue;
};
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19897243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档