构造无参,出现1111.exe - 1 error(s), 0 warning(s)?这是什么情况?

#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.cpp
D:\软件\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/union
D:\软件\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/union
D:\软件\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 called
D:\软件\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)

慕少森
浏览 313回答 2
2回答

婷婷同学_

两种办法,办法一,你在类里面添加如下无惨构造函数代码:AA(){}办法二,把这个AA(int&nbsp;i,int&nbsp;j)修改成带缺省参数的函数AA(int&nbsp;i=0,int&nbsp;j=0)&nbsp;&nbsp;然后把main函数修改如下:&nbsp;&nbsp;void&nbsp;main(){AA&nbsp;a1,a2;a1.rint();a2.print();}&nbsp;&nbsp;还有最简单的办法,直接把main函数修改如下:&nbsp;&nbsp;void&nbsp;main(){AA&nbsp;*a1,*a2;a1=new&nbsp;AA(1,2);a2=new&nbsp;AA(5,6);a1->print();a2->print();delete&nbsp;a1;delete&nbsp;a2;}

慕神8447489

AA(int i,int j)你不是说要构造无参吗?怎么这个地方又有参数呢,看你标题知道你什么意思,但是看你程序就混啦…
打开App,查看更多内容
随时随地看视频慕课网APP