我在.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
Simulator(int,int,const std :: string);
^
./ TP1.h:10:7:注意:候选构造函数(隐式副本 构造函数)不可行:需要1个参数,但提供0
为什么g ++找不到构造函数?
答案 0 :(得分:0)
没关系。我使用的参数少于要求。