日系奥利奥 2022-09-30 09:34 采纳率: 90.9%
浏览 18
已结题

在主函数中错误使用了test类 看看哪里的问题

#include
using namespace std;
class Test
{public:Test(int aa=1):a(aa){}
Test(){}
void putOut()const{cout<<a<<","<<b<<endl;}
private:int a;
static int b;
};
int Test::b=2;
void main()
{ Test t1();
t1.putOut();
const Test t2(2);
t2.putOut();
}

img

  • 写回答

1条回答 默认 最新

  • _DJ 2022-09-30 09:45
    关注

    Test t1(1);,生成对象时要给予参数,当你的构造函数只有一个形参时,就算你给予了默认值,编译器也是不认识的。且Test t1();是仿函数的写法,即重载了(),不会调用无参构造函数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月9日
  • 已采纳回答 10月1日
  • 创建了问题 9月30日