I have an instance of a class in this 'cpu.h' and it is from 'ir.h' it worked like this for a while and then just went crazy with errors, nothing looks out of place I have looked at solutions for similar problems, but nothing has helped so far.
class Cpu {
public:
Cpu();
//Initialize member variables.
bool load(char filename[]);
//loads instructions from given file into memory (and they're automatically displayed)
//returns true if successful, false otherwise
int hexstrToInt(char inStr[]);
// converts hex string to integer
// eg. "0"->0, “0a”->10, "ff"->255
// Value must be less than MAX_INT
void execute(unsigned char& opCode, int& regR, int& regS,int& regT, unsigned char& XY);
// executes the given instruction and if it’s NOT a jump
// instruction, adds two to the program counter.
void run();
//Loads, Decodes, and Executes instructions until
//halt instruction is encountered.
//destructor
~Cpu();
private:
char filename[80]; //file we're processing
Cell reg[MAX_REGS]; //registers
Cell* mem[MAX_MEM]; //memory
Cell PC; //program counter
Ireg irReg; ////!!!!!!error occurs here
//other will be added in future assignments
class Ireg : public Cell
{
public:
Ireg(unsigned short opCode=0);
//initialize member variables
void load(unsigned char highByte, unsigned char lowByte);
// Loads given data into mOpCode (highByte goes into the upper
// 8 bits and lowByte goes into the lower 8 bits)
// Erases description and updates the screen (calls show).
void decode(unsigned char& opCode, int& regR, int& regS, int& regT, unsigned char& XY);
// Decodes mOpCode, creates description, calls show(),
// and returns the appropriate parts (via ref variables).
// Variables that don’t apply have zeros returned in them
private:
unsigned short mOpCode;
//two bytes, stores OpCode.
char mDesc[20];
//description of opcode and operands
void show();
// Displays mOpCode contents on screen at specified position
// using specified colors. And displays the desc (which may
// or may not be blank) a few bytes to the right
If, in a translation unit, "ir.h" is #included before "cpu.h", then this error will occur. This is because, in "ir.h", which contains the declaration of Ireg, it will #include "cpu.h" which refers to Ireg but the declaration of Ireg hasn't been #included yet.
Solution 1: Take #include "cpu.h" out of "ir.h" (Cpu doesn't seem to be used there)
Solution 2: Make sure that wherever you #include "ir.h", you #include "cpu.h" before it. This may be a sign that you have to restructure your objects' relationships.