2012-09-04 209 views
0

我碰到下面的錯誤,我想不通爲什麼:找不到匹配

Could not find a match for 'PEmployee::PEmployee(char *, double)' in function main() 

這裏是我的代碼:

class PEmployee 
{ 
    public: 
     PEmployee(); 
     PEmployee(string employee_name, double initial_salary); 
     void set_salary(double new_salary); 
     double get_salary() const; 
     string get_name() const; 
    private: 
     Person person_data; 
     double salary; 
}; 

int main() 
{ 
    PEmployee f("Patrick", 1000.00); 
    cout << f.get_name() << " earns a salary of "; 
    << f.get_salary() << endl; 
    return 0; 
} 

有人能告訴我爲什麼我得到這個錯誤?

謝謝。

+1

是否定義了'string'? – chris

+0

備註與手邊的問題無關:''在'「之後''應該沒有分號';'因爲表達式繼續到下一行,所以薪水爲'''。 – jogojapan

回答

1

std::stringchar *類型的構造函數不是顯式的,所以我不知道爲什麼你會得到這個錯誤。編譯器應該認識到它可以爲你創建一個std::string

http://en.cppreference.com/w/cpp/string/basic_string/basic_string

basic_string的(常量圖表* S, 常量分配器&的alloc =分配器());

+0

也許'string'實際上並不是'std :: string'這裏。 – jogojapan

+0

或者它只是在另一個標題中向前聲明(例如'')。 – MSalters