#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; } |
- 2 回答
- 0 关注
- 305 浏览
添加回答
举报
0/150
提交
取消