【发布时间】:2014-10-13 09:34:24
【问题描述】:
我对这段代码中构造函数的行为感到困惑。
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&) 中没有参数名可以吗?如果是,这样的构造函数有什么用?
【问题讨论】:
-
two不是变量。这是一个函数。 -
htc two();声明了一个名为two的函数,它返回htc类型
标签: c++ constructor