Reputation: 103
I keep getting errors when I try to build headers, classes and constructors. Dev C++ gives me a bunch of errors, and I don't know how to resolve them. I've included the errors as comments in the code:
Test.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;
}
I don't get it. What am I doing wrong?
Upvotes: 0
Views: 111
Reputation: 42215
You need a ;
at the end of your declaration of Object
class Object
{
....
};
Upvotes: 5