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

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

求typedef Stack<int> IntStack; IntStack s; 這樣實例化對嗎?

求typedef Stack<int> IntStack; IntStack s; 這樣實例化對嗎?

白板的微信 2022-05-12 17:11:22
#include<iostream>using namespace std;template<class Type>class Stack{private:int top;Type *stacka;//用數(shù)組存儲棧的元素int maxSize;public:Stack(int Size);//~Stack(){delete[] stack;}void push(const Type &item);Type pop(void);Type getTop();int empty(void) const{return top==-1;}int full(void) const{return maxSize-1;}void clear(void){top==-1;}};template<class Type>void Stack<Type> ::push(const Type &item){if(full()){cout<<"stack is full"<<endl;exit(1);}top++;stacka[top]=item;}template<class Type>Type Stack<Type> ::pop(){if(empty()){cout<<"stack is empty!"<<endl;exit(1);}Type data=stacka[top];//棧不空,取棧頂元素top--;return 0;//返回棧頂元素}template<class Type>Type Stack<Type> ::getTop(){if(empty()){cout<<"stack is empty!"<<endl;exit(1);}return stacka[top];//棧不空,取棧頂元素}int main(){typedef Stack<int> IntStack;IntStack s;for(int i=0;i<10;i++){s.push(i);}for(int i=0;i<10;i++){cout<<"翻轉后:"<<s.pop()<<endl;}}報錯是45 cpp no matching function for call to `Stack<int>::Stack()'cpp:4 candidates are: Stack<int>::Stack(const Stack<int>&)
查看完整描述

2 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經(jīng)驗 獲得超3個贊

0、構造函數(shù)不匹配,需要傳參,或者構造函數(shù)中設置參數(shù)默認值,比如 Stack(int Size=10);
1、缺少構造函數(shù)的定義
2、函數(shù)full中邏輯錯誤,可能改為maxSize-1==top;(跟maxsize的初始化值有關)
3、函數(shù)pop返回值錯誤,應該返回data
錯誤大體如上,其他你自己再看看吧。

查看完整回答
反對 回復 2022-05-16
?
莫回無

TA貢獻1865條經(jīng)驗 獲得超7個贊

你構造函數(shù)沒定義,但是你的構造函數(shù)把空參構造函數(shù)取代了

查看完整回答
反對 回復 2022-05-16
  • 2 回答
  • 0 關注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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