#include <iostream> using namespace std; class Obj { public: Obj(){cout <<"create obj" << endl;} Obj(const Obj& other){cout<<"copy create obj"<<endl;} ~Obj(){cout<<"destructed obj"<<endl;} }; int main() { Obj(Obj((Obj()))); cout<<"---- exit main ----"<<endl; }
I have no idea why this program only prints 1 create obj and 1 destructed obj. Reference.
Due to copying Elision. More on this. Your compiler understands that he can avoid copying the object around and just creates one object.
Source: https://habr.com/ru/post/1687850/More articles:How do you determine the development mode in Expo? - react-nativeJava DateTimeFormatterBuilder with detailed timezone - javaC ++ Struct completes POD check - c ++swift 3, ios 10 - push basebase not accepted - iosCan dplyr :: case_when return a NA and non-NA connection? - rDifferent value of property for contracts - c #Downloading multiple gifs multiple times - javascriptDocker: log capture error: invalid character '\ x00' looking for start of value - dockerPointer Arithmetic - Identical Expressions? - c ++Можно ли использовать карту/фильтр/уменьшить внутри обещания, возвращая результат с помощью Promise.resolve? - javascriptAll Articles