为什么没有构造函数被调用?

时间:2019-08-01 17:46:40

标签: c++ c++11 copy-constructor move-constructor copy-elision

class X {
public:
    X() {}
    X(const X&) {
        std::cou << "copy constructor";
    }
    X(X&&) {
        std::cout << "move constructor";
    }
};

X func() { return X(); }

int main() {
    X x(func()); // nothing is printed
}

我认为必须调用move构造函数,但是复制构造函数和move构造函数都不会被调用。这是因为抄袭吗?

0 个答案:

没有答案
相关问题