我是Cpp编程的新手,我正在做一个程序,该程序必须包含一个名字,性别,年龄和人的电话号码。
我有三个错误。
有我的计划:
enter code here
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class infoPersonne
{
char *nom [40];
char *sexe;
int age;
char *notel [12];
public:
infoPersonne(char * , char *, int , char *);
infoPersonne();
infoPersonne(infoPersonne &ip);
~infoPersonne();
void affiche();
};
infoPersonne::infoPersonne(char *n, char *s, int a, char *nt) // contructeur
{
std::string nom=n;
std::string sexe=s;
age=a;
std::string notel=nt;
cout<< "construction de l'information d'une personne"<<endl;
}
infoPersonne::infoPersonne( infoPersonne &ip) // constructeur par recopie
{
std::string nom = ip.nom;
std::string sexe = ip.sexe;
age=ip.age;
std::string notel=ip.nt;
}
infoPersonne::infoPersonne() // constructeur par défaut
{
std::string nom = "";
std::string sexe = "";
age = 0;
std::string notel = "0";
}
infoPersonne:: ~infoPersonne() // destructeur
{
cout<<"destruction de l'information d'une personne"<<endl;
delete []nom;
delete sexe;
delete []notel;
}
void infoPersonne:: affiche()
{
cout << endl << "Nom :" << nom
<< endl << "Sexe :" << sexe
<< endl << "Age :" << age
<< endl << "Telephone : " << notel << endl;
}
using namespace std;
int main(int argc, char *argv[])
{
infoPersonne A();
infoPersonne B("Louise Messier","F",54, "514-756-8890");
A.affiche();
B.affiche();
system("PAUSE");
return EXIT_SUCCESS;
}
我的第一个错误出现在构造函数的行上,在特定行std :: string nom = ip.nom上复制infoPersonne :: infoPersonne(infoPersonne&amp; ip)。错误是:来自&#39; char * [40]&#39;到非标量类型&#39; std :: string {aka std :: basic_string}&#39;要求| 我还有另一个错误:&#39; class infoPersonne&#39;没有名为&#39; nt&#39;但成员nt是否已定义? 第三个是:请求会员&#39; affiche&#39; in&#39; A&#39;,这是非类型&#39; infoPersonne()&#39; |
你能帮帮我吗?先感谢您。答案 0 :(得分:-1)
代码存在许多问题。看看你是否可以先获得更少的代码。如何从main调用一个函数,传入stings和char数组指针,这样你就可以降低该技能。