2012-11-03 92 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

沒關係。我使用的參數少於需要的數量。