第一种写法
#include
using namespace std;
class Student{
private:
char *m_name;
int m_age;
float m_score;
public:
Student(char *name,int age ,float score);
void show();
};
//采用初始化列表
Student::Student(char *name,int age ,float score):m_name(name),m_age(age),m_score(score){}
void Student::show(){
cout<show();
return 0;
}
第二种写法
#include
#include
using namespace std;
class Student{
private:
string m_name;
int m_age;
float m_score;
public:
Student(string name, int age, float score);
void show();
};
//采用初始化列表
Student::Student(string name, int age, float score){
//;
m_name=name;
m_age=age;
m_score=score;
}
void Student::show(){
cout< show();
return 0;
}
第三种写法
#include
using namespace std;
class Student{
private:
char *m_name;
int m_age;
float m_score;
public:
Student(char *name,int age ,float score);
void show();
};
//采用初始化列表
Student::Student(char *name,int age ,float score):m_name(name){
m_score=score;
m_age=age;
}
void Student::show(){
cout<show();
return 0;
}