2012-11-03 52 views
0

没有匹配的构造我有在.h以下类:G ++初始化

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: 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 provided

Simulator (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

为什么不是g ++找到构造函数?

回答

0

没关系。我使用的参数少于需要的数量。