c++ - 找不到匹配项

标签 c++ class match

我收到以下错误,我无法弄清楚原因:

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;
}

有人能告诉我为什么会出现这个错误吗?

谢谢。

最佳答案

类型为 char *std::string 的构造函数不是显式的,所以我不知道为什么会出现该错误。编译器应该认识到它可以为您即时创建一个 std::string

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

basic_string( const CharT* s, const Allocator& alloc = Allocator() );

关于c++ - 找不到匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12256243/

相关文章:

c++ - 内部和外部重载 C++ 运算符之间的区别

c++ - Sqlite根据点信息生成距离表

c++ - 从外部类访问嵌套的内部类结构

c++ - 在函数 undefined reference 中 C++

c++ - 检查 C++ 成员函数是否存在,可能 protected

python - 在 Python 或 C++ 中打开 Maya callBacks 查询内存中的所有回调

c# - session 存储与类存储

MySQL:在 JOIN 中合并

regex - Scala列表匹配正则表达式

regex - 如何匹配字母组合及其出现次数