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

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

谢谢。

4

1 回答 1

1

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

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

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

于 2012-09-04T03:10:46.400 回答