I am receiving the following errors when running my code and it seems as if I had tried everything to eliminate them but nothing is appearing to work. Any suggestions or explanation of what I be may doing wrong would be greatly appreciated. Here are the errors: In my code at "class Integer : public Number" it says "! Expected class name" and at "Integer(const Double &d);" it says "! Unknown type name 'Double'; did you mean 'double'?"
Here is may actual code in Integer.h which contains the errors:
#ifndef INTEGER
#define INTEGER
#include "Number.h"
#include "Double.h"
namespace MyNamespace {
using std::string;
class Double;
class Integer : public Number
{
private:
void create(int i);
bool NaN(string s, int iCount);
bool nan;
public:
//Constructors
Integer();
Integer(int i);
Integer(const Integer &i);
Integer(const Double &d); //ERROR HERE = "Unknown type 'Double'"
Integer(string s);
void equals(int i);
void equals(string s);
Integer add(const Integer &i);
Integer sub(const Integer &i);
Integer mul(const Integer &i);
Integer div(const Integer &i);
Integer add(int i);
Integer sub(int i);
Integer mul(int i);
Integer div(int i);
int toInt() const;
//Print
void printInteger();
// operator overloads
Integer operator + (const Integer &i);
Integer operator - (const Integer &i);
Integer operator * (const Integer &i);
Integer operator / (const Integer &i);
Integer operator = (const Integer &i);
Integer operator = (int i);
Integer operator = (string s);
string toString() const;
bool operator == (const Integer &i);
bool operator == (int i);
bool operator != (const Integer &i);
bool operator != (int i);
bool isNan();
};
}
#endif
Number.h
#ifndef NUMBER
#define NUMBER
#include <iostream>
#include <string>
namespace MyNamespace {
using std::string;
class Number : public string
{
public:
Number();
Number(string s);
};
}
#endif
Double.h
#ifndef DOUBLE
#define DOUBLE
#include "Number.h"
#include "Integer.h"
namespace MyNamespace
{
class Integer;
class Double : public Number
{
private:
void create(double d);
bool NaN(string s, int dCount);
bool nan;
public:
// Constructors
Double();
Double(double d);
Double(const Double &d);
Double(const Integer &i); //ERROR HERE = "Unknown type 'Integer'"
Double(string s);
void equals(double d);
void equals(string s);
Double add(const Double &d);
Double sub(const Double &d);
Double mul(const Double &d);
Double div(const Double &d);
Double add(double d);
Double sub(double d);
Double mul(double d);
Double div(double d);
double toDouble() const;
//Print
void printDouble();
// operator overloads
Double operator + (const Double &d);
Double operator - (const Double &d);
Double operator * (const Double &d);
Double operator / (const Double &d);
Double operator = (const Double &d);
Double operator = (double d);
Double operator = (string s);
string toString() const;
bool operator == (const Double &d);
bool operator == (double d);
bool operator != (const Double &d);
bool operator != (double d);
bool isNan();
};
}
#endif
Simplify Number.h. Don't include "Integer.h" and "Double.h" in it. You are not even referencing anything from those files in this file.
Remove
#include "Integer.h"
from Double.h. Similarly, remove#include "Double.h"
from Integer.h. Add a forward declaration ofInteger
in Double.h and a forward declaration ofDouble
in Integer.h.I would wager that Number and Double, if defined at all, are defined in a namespace and need to be qualified.
You have a circular dependency between Integer and Double. If you do not utilize these inline you might just have a forward declarations and remove the #include "Integer.h" and #include "Double.h".
If you want to use these inline you might include additional files for the inline implementations: