gpt4 book ai didi

c++ - 使用默认构造函数初始化对象

转载 作者:搜寻专家 更新时间:2023-10-31 00:19:28 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Most vexing parse: why doesn't A a(()); work?
Difference between creating object with () or without

有这样的代码:

class MojaKlasa{
public:
MojaKlasa(){}
MojaKlasa(int i){}
void fun(){}
};

int main()
{
MojaKlasa a;
a.fun();

MojaKlasa b(1);
b.fun();

MojaKlasa c(); // initialize with default constructor
//c.fun(); error: request for member ‘fun’ in ‘c’, which is of non-class type ‘MojaKlasa()’

return 0;
}
  • 为什么对象c 有错误?
  • 让它发挥作用的方法是什么?
  • MojaKlasa c() 的真正含义是什么 - 它是函数声明吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com