第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

想要建立一個對象數(shù)組,內(nèi)放5個學(xué)生的數(shù)據(jù)(學(xué)號成績),請問我的程序錯在哪里?

想要建立一個對象數(shù)組,內(nèi)放5個學(xué)生的數(shù)據(jù)(學(xué)號成績),請問我的程序錯在哪里?

C++ C
慕容3067478 2022-01-04 19:15:35
#include<iostream>using namespace std;class Student{public:Student(int,int);void display();private:int number;int score;};Student::Student(int a,int b){number=a;score=b;}void Student::display(){cout<<number<<":"<<score<<endl;} int main(){Student* p;p= new Student[5]; //為什么總是提示沒有合適的構(gòu)造函數(shù),這里我是想動態(tài)建立一個包含5個對象對象數(shù)組,并用指針指向首對象,并不是想調(diào)用構(gòu)造函數(shù)Student student[5]={Student(1,89),Student(2,92),Student(3,98),Student(4,95),Student(5,81)}; int i;for(i=0;i<5;i=i+2){p[i].display();}cout<<endl;delete p;return 0;}
查看完整描述

3 回答

?
長風(fēng)秋雁

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個贊

構(gòu)造函數(shù)不對,是兩個參數(shù)(int,int)。
所有你得:
p=new Student(1,1)[5];
否則自己加一個構(gòu)造函數(shù)
Student::Student();
然后再加一個輸入的函數(shù)input(...);
才能p=new Student()[5];
*(p+1).input(...);

查看完整回答
反對 回復(fù) 2022-01-09
?
元芳怎么了

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個贊

Student* = new Student[5];

要那樣開辟內(nèi)存,你必須要有默認(rèn)參數(shù)的構(gòu)造函數(shù),就是說


class Student{public:Student(); // 默認(rèn)參數(shù)的構(gòu)建(比如,默認(rèn)name,0分)Student(int,int);void display();private: int number; int score;};


查看完整回答
反對 回復(fù) 2022-01-09
?
桃花長相依

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個贊

Student()
{}
自己再加一個空構(gòu)造函數(shù),當(dāng)你自己定義構(gòu)造函數(shù)時,系統(tǒng)不再生成默認(rèn)空構(gòu)造函數(shù)!

查看完整回答
反對 回復(fù) 2022-01-09
  • 3 回答
  • 0 關(guān)注
  • 430 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號