gpt4 book ai didi

没有参数名称的C++构造函数

转载 作者:行者123 更新时间:2023-11-28 06:38:45 24 4
gpt4 key购买 nike

<分区>

我对这段代码中构造函数的行为感到困惑。

class htc {
public:
htc() { std::cout << "HTC_FOO_CONSTRUCTOR" << std::endl ;}
htc(const htc&) { std::cout << "HTC_BAR_CONSTRUCTOR" << std::endl;};
};

int main()
{
htc one; // This outputs HTC_FOO_CONSTRUCTOR
htc two(); // This outputs nothing
htc three(one)
}

几个问题在 htc two() 中使用括号是什么意思? & 在构造函数 htc(const htc&) 中没有参数名称可以吗?如果是,这样的构造函数有什么用?

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