为了账号安全,请及时绑定邮箱和手机立即绑定

构造无参,出现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 关注
  • 305 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信