|
#include <iostream>
#include <string>
using namespace std;
class CStudent
{
private:
string name;
char sex;
int num;
int age;
public:
/*void pringf(string P_name,char P_sex, int P_num,int P_age)
{
name = P_name;
sex = P_sex;
num = P_num;
age = P_age;
cout << "学生的名字:" << name << endl;
cout << "学生的性别:" << sex << endl;
cout << "学生的学号:" << num << endl;
cout << "学生的籍贯:" << age << endl;
}*/
void pringf(string *P_name, char *P_sex, int *P_num, int *P_age)
{
name =* P_name;
sex = *P_sex;
num = *P_num;
age = *P_age;
cout << "学生的名字:" << name << endl;
cout << "学生的性别:" << sex << endl;
cout << "学生的学号:" << num << endl;
cout << "学生的籍贯:" << age << endl;
}
};
int main()
{
CStudent std_1;
std_1.pringf("li_si",'f',1005418,30); // 这里报错了,
return 0;
}
实参与形参不兼容怎么才能运行呢?
- string name = "li_si";
- char sex = 'f';
- int num = 1005418;
- int age = 30;
- std_1.pringf(&name,&sex, &num, &age);//&取变量地址,你参数才能用指针
复制代码
多嘴一句,你写的这代码,不懂有何意义。你如果是要给类成员初始化,也不应该这样操作的。
|
上一篇: 重叠I/O WSAWaitForMultipleEvents()一直失败的问题下一篇: 我的输出怎么不一样,帮我改一改
|