亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

初始化列表問題

#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.

這是為什么....

正在回答

1 回答

Student s2(); 把小括號去掉

0 回復 有任何疑惑可以回復我~
#1

Maseghini4089428 提問者

對對對 是對的
2017-05-17 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
C++遠征之封裝篇(上)
  • 參與學習       103391    人
  • 解答問題       732    個

封裝--面向對象的基石,本教程力求幫助小伙伴們即學即會

進入課程

初始化列表問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號