1 个回答
氢气
回答于 2024-07-20
已采纳
提问:main()创建了一个自定义的Base类型语法不通过。求修正一下
#include<stdio.h>#include<windows.h>class Base{private:int i;int j;public: Base(int i,int j) { this -> i = i;this -> j = j; }bool operator>(Base&base){ return this->i >base.i && this->j > base.j ;}};template<class T>void sort(T*arr,int nlength){int i;int j; T temparr;for(i=0;i<nlength-1;i++){for(j=0;j<nlength-1;j++){if(arr[j] > arr[j+1]){ temparr = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temparr;}}}}int main(){//char arr[] ={1,4,3,2,5,6,8,7};// sort(arr,8);Base b1(1,1),b2(3.3);//Base arr1[] ={b1,b2};//sort(arr1,2);return 0;}
网友回答:
对你上面的程序,只是符号写错了
Base b1(1,1),b2(3.3);
应该是
Base b1(1,1),b2(3,3); //3 3间只能逗号
而若把注释去掉,你的Base缺少缺省构造
我来回答
相关问题
1
回答
游戏王卡组推荐
单机游戏
567 浏览