“Student::Student(int,char,char)”: 不能将参数 2 从“const char [8]”转换为“char” 1>
#include<iostream>usingnamespacestd;classStudent{public:Student(intn,charnam,chars){n...
#include <iostream>
using namespace std;
class Student
{
public:
Student(int n,char nam,char s)
{
num=n;
name=nam;
sex=s;
cout<<"constructor called."<<endl;
}
~Student()
{
cout<<"destructor called."<<endl;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
private:
int num;
char name;
char sex;
};
int main()
{
Student stud1(10,"wang_li",'f');
stud1.display();
Student stud2(11,"zang_li",'c');
stud2.display();
return(0);
} 展开
using namespace std;
class Student
{
public:
Student(int n,char nam,char s)
{
num=n;
name=nam;
sex=s;
cout<<"constructor called."<<endl;
}
~Student()
{
cout<<"destructor called."<<endl;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
private:
int num;
char name;
char sex;
};
int main()
{
Student stud1(10,"wang_li",'f');
stud1.display();
Student stud2(11,"zang_li",'c');
stud2.display();
return(0);
} 展开
展开全部
不得不陪你是个才人,首先是名字;你 定义一个字符,那只能放子一个字母;要不就定义成字符串,要不就定义成字符指针;其次就是在写函数的参数时,要不就定义成引用,要不就定义成指针;如果不求返回,你可以直接定义成你的模样;
追问
怎么改,谢谢
追答
#include
using namespace std;
class Student
{
public:
Student(int &n,char *nam,char* s)
{
this->num=n;
this->name=nam;
this->sex=s;
cout<<"constructor called."<<endl;
}
~Student()
{
cout<<"destructor called."<<endl;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<*name<<endl;
cout<<"sex:"<<*sex<<endl;
}
private:
int num;
char *name;
char *sex;
};
int main()
{
Student stud1(10,"wang_li",'f');
stud1.display();
Student stud2(11,"zang_li",'c');
stud2.display();
return(0);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询