Explicit type is missing (int assumed)

倖福魔咒の 提交于 2020-01-05 08:36:32

问题


I don't get what I'm doing wrong. It's a really simple program I made to practice using headers, classes and constructors. It says that I'm not missing a return type for the function getValue() in Header2.cpp. I have no idea how to fix it. Any ideas?

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;
};

回答1:


you are missing an int

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



回答2:


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

Should be:

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


来源:https://stackoverflow.com/questions/19897243/explicit-type-is-missing-int-assumed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!