C++关于构造方法中给char *型赋值的问题
程序代码:class Student
{
public:
Student(char *name = "qwe", int stature = 180, int avoirdupois = 75);
Student(const Student &stu);
public:
~Student(void);
private:
char * m_name;
int m_stature, m_avoirdupois;
};
Student::Student(char *name, int stature, int avoirdupois)
{
this->m_name = new char[sizeof(name)];
*(this->m_name) = *name;
this->m_stature = stature;
this->m_avoirdupois = avoirdupois;
cout << "缺省构造函数" << endl;
cout << "姓名:" << *(this->m_name) <<",身高:" << this->m_stature << ",体重:" << this->m_avoirdupois << endl;
}为什么打印出来只有一个字符q?



