Ken*_*lor 6 c++ compiler-construction
我以前从未在C++中遇到过这个问题,但奇怪的是它仍然可以编译,但却没有达到我的预期.有人能告诉我它做了什么吗?请参阅代码,更多信息如下.
#include <iostream>
using namespace std;
class Test{
public:
Test();
};
Test::Test(){ cout << "ctor" << endl; }
int main(void){
Test t(); // this compiles but doesn't call the constructor
return(0);
}
Run Code Online (Sandbox Code Playgroud)
它会编译,但如果我尝试使用"t"则不会.我只依赖于构造函数,我的代码没有按预期工作.解决方案是丢失括号"Test t();" "测试t;".我的问题是"测试t();" 例如,编译器认为它正在发生什么,它允许它编译.
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |