I have the following classes in a .h:
class Register {
int content;
public:
Register ();
}reg;
class Simulator {
int op1, op2, initial_pos;
Register RA, RB, RC, RD, PC, SP, FP;
bool zero, neg;
int mem[1024];
public:
Simulator (int, int, const std::string);
void Memdump ();
void Exec_next ();
}sim;
and the definition for the simulator constructor is as follows:
Simulator::Simulator (int i, int j, int k, std::string fname) {
FILE* instructions;
valA = 0;
valB = 0;
valC = 0;
valP = 0;
valE = 0;
op1 = 0;
op2 = 0;
zero = false;
neg = false;
valid1 = false;
valid2 = false;
PC::content = 0;
FP::content = j;
SP::content = j;
initial_pos = k;
for (int i = 0; i < 1024; i++)
mem[i] = 0;
//Read input file
if (instructions = fopen (filename, 'r') == NULL) {
cout << "Error 404: file not found\n";
exit (404);
}
for (int i = 0; !feof (instructions); i++)
fscanf (instructions, "%d\n", &(mem[i + initial_pos]) );
fclose (instructions);
}
but when i try to compile this code i get the following error message:
./TP1.h:45:2: error: no matching constructor for initialization of
‘class Simulator’}sim;
^
./TP1.h:42:3: note: candidate constructor not viable: requires 3
arguments, but 0 were providedSimulator (int, int, const std::string);
^
./TP1.h:10:7: note: candidate constructor (the implicit copy
constructor) not viable: requires 1 argument, but 0 were provided
why isn’t g++ finding the constructor?
Nevermind. I’m using 1 less argument than required.