初始化列表问题
#include<iostream>
#include<string>
using namespace std;
class Student{
private:
string m_strName;
int m_iAge;
public:
Student() :m_strName("Name"), m_iAge(1){
cout << "初始化列表0" << endl;
}
Student(string name,int age):m_strName(name), m_iAge(age){
cout << "初始化列表" << endl;
}
void getName(){
cout << m_strName << endl;
}
void getAge(){
cout << m_iAge << endl;
}
};
int main(){
Student s1("Cjj",12);
s1.getName();
Student s2();
s2.getName();
}
//s2.getName(); 报错 expession must have class type.
这是为什么....