为什么构造函数没有使用函数调用运算符调用

时间:2015-06-02 14:57:46

标签: c++ constructor

抱歉,我无法找到任何关键字来搜索此问题。我的代码在

之下
#include <iostream>
using namespace std;
class Name {
    public:
        Name() {
            cout << "Asif";
        }
};

int main() {
    Name obj(); // why Constructor not calling here?

    return 0;
}

如果它没有调用构造函数,那么这段代码中正在运行什么进程?

1 个答案:

答案 0 :(得分:3)

 Name obj(); // why Constructor not calling here? 

这是一个函数声明,返回一个Name对象

只做

Name obj;