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

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

構造無參,出現1111.exe - 1 error(s), 0 warning(s)?這是什么情況?

構造無參,出現1111.exe - 1 error(s), 0 warning(s)?這是什么情況?

慕少森 2022-05-13 11:11:02
#include<iostream.h>class AA{public:AA(int i,int j){A=i;B=j;cout<<"Constructor.\n";}~AA(){cout<<"Destructor.\n";}void print();private:int A,B;};void AA::print(){cout<<A<<","<<B<<endl;}void main(){AA a1,a2;a1=new AA(1,2);a2=new AA(5,6);a1->print();a2->print();delete a1;delete a2;}錯誤提示是:--------------------Configuration: 1111 - Win32 Debug--------------------Compiling...1111.cppD:\軟件\VC6\MyProjects\1111\1111.cpp(22) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class AA *' (or there is no acceptable conversion)D:\軟件\VC6\MyProjects\1111\1111.cpp(23) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class AA *' (or there is no acceptable conversion)D:\軟件\VC6\MyProjects\1111\1111.cpp(24) : error C2819: type 'AA' does not have an overloaded member 'operator ->'D:\軟件\VC6\MyProjects\1111\1111.cpp(3) : see declaration of 'AA'D:\軟件\VC6\MyProjects\1111\1111.cpp(24) : error C2227: left of '->print' must point to class/struct/unionD:\軟件\VC6\MyProjects\1111\1111.cpp(25) : error C2819: type 'AA' does not have an overloaded member 'operator ->'D:\軟件\VC6\MyProjects\1111\1111.cpp(3) : see declaration of 'AA'D:\軟件\VC6\MyProjects\1111\1111.cpp(25) : error C2227: left of '->print' must point to class/struct/unionD:\軟件\VC6\MyProjects\1111\1111.cpp(26) : error C2440: 'delete' : cannot convert from 'class AA' to ''No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledD:\軟件\VC6\MyProjects\1111\1111.cpp(26) : fatal error C1903: unable to recover from previous error(s); stopping compilation執行 cl.exe 時出錯.1111.exe - 1 error(s), 0 warning(s)
查看完整描述

2 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊


兩種辦法,辦法一,你在類里面添加如下無慘構造函數代碼:AA(){}辦法二,把這個AA(int i,int j)修改成帶缺省參數的函數AA(int i=0,int j=0)  然后把main函數修改如下:  void main(){AA a1,a2;a1.rint();a2.print();}  還有最簡單的辦法,直接把main函數修改如下:  void main(){AA *a1,*a2;a1=new AA(1,2);a2=new AA(5,6);a1->print();a2->print();delete a1;delete a2;}


查看完整回答
反對 回復 2022-05-16
?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

AA(int i,int j)
你不是說要構造無參嗎?怎么這個地方又有參數呢,看你標題知道你什么意思,但是看你程序就混啦…

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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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