C++: Calling a constructor to a temporary object

后端 未结 3 1162
天涯浪人
天涯浪人 2021-01-19 17:17

Suppose I have the following:

int main() {
    SomeClass();
    return 0;
}

Without optimization, the SomeClass() constructor will be calle

3条回答
  •  自闭症患者
    2021-01-19 17:56

    I'm sure is 'SomeClass::SomeClass()' is not implemented as 'inline', the compiler has no way of knowing that the constructor/destructor has no side effects, and it will call the constructor/destructor always.

提交回复
热议问题