我是C ++的初级和我正在制作程序,通过转换到我班级的方法来显示一些数据。它还没有真正完成,但是当我创建一个类对象时,它在“Passport Info”行中向我说“没有匹配的调用函数”。这是我的代码:
#include <iostream>
#include <string>
using namespace std;
class Passport {
private:
int _size = 6;
std::string* class_people;
std::string* class_birth;
std::string people[6] = {
"bro1", "bro2", "bro3", "bro4", "bro5", "bro6"
};
std::string birth[6] = { "1995", "1994", "1996", "1994", "2001", "1990" };
public:
Passport(std::string people, std::string birth)
{
class_people = new string[_size];
class_birth = new string[_size];
for (int ix = 0; ix < _size; ix++) {
class_people[ix] = people[ix];
class_birth[ix] = birth[ix];
}
}
void show_data()
{
for (int px = 0; px < _size; px++) {
cout << class_people[px] << endl;
cout << class_birth[px] << endl;
}
}
};
int main()
{
setlocale(LC_ALL, "Russian");
Passport Info;
Info.show_data();
system("pause");
return 0;
};
另外,我想在Passport类的私有部分指向我的字符串变量,以便在构造函数中使用但是如何?感谢。
答案 0 :(得分:1)
问题是你的Passport
类没有Passport Info;
试图调用的默认构造函数。
向Passport
类添加默认构造函数或向Passport Info;
添加一些参数例如:
int main()
{
setlocale(LC_ALL, "Russian");
Passport Info("Vladimir", "1995");
Info.show_data();
system("pause");
return 0;
};