Explicit type is missing (int assumed)

2019-08-15 08:09发布

问题:

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