如何用c ++中的参数构造一个对象

Sea*_*n M 0 c++ constructor

我不断收到此错误:no matching function for call to 'Person::Person(const char [10]) 该类位于单独的cpp文件中.当我在同一个cpp文件中有构造函数时,我可以轻松地创建一个对象.这是我的代码:

main.cpp文件

#include <iostream>
#include "Person.h"

using namespace std;

int main()
{
    Person p("hellooooo");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Person.h文件

#ifndef PERSON_H
#define PERSON_H


class Person
{
    public:
        Person();
    protected:
    private:
};

#endif // PERSON_H
Run Code Online (Sandbox Code Playgroud)

Person.cpp文件

#include <iostream>
#include "Person.h"

using namespace std;

Person::Person()
{
   cout << "this is the default constructor??";
}

Person::Person(string n)
{
   cout << n;
}
Run Code Online (Sandbox Code Playgroud)

Ria*_*iaD 6

你必须在你的.h文件中添加第二个构造函数的声明

#include <string>
class Person
{
    public:
        Person();
        Person(std::string);
};
Run Code Online (Sandbox Code Playgroud)