我在 .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;
模拟器构造函数的定义如下:
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);
}
但是当我尝试编译此代码时,我收到以下错误消息:
./TP1.h:45:2:错误:没有匹配的构造函数用于初始化“类模拟器”
}sim;
^
./TP1.h:42:3:注意:候选构造函数不可行:需要 3 个参数,但提供了 0 个参数
模拟器 (int, int, const std::string);
^
./TP1.h:10:7:注意:候选构造函数(隐式复制构造函数)不可行:需要 1 个参数,但提供了 0 个参数
为什么 g++ 没有找到构造函数?