0

Creating object in c++

if i have a class like this class Example{ public: int y; Example(int x){y = x;} }; and in main function i try to create two objects with difference ways Example a = Example(3); Example b(Example(3)); I know that i can use "Example a(3)" to create object,but what is the difference between object a and b?are they the same?if not,whats the differencd

4th Apr 2020, 4:27 PM
durian
durian - avatar
2 Respostas
+ 1
They are the same, optimization ( copy elision ) makes sure only 1 object is constructed. Only difference is that they use uglier syntax, but that's just my opinion.
4th Apr 2020, 5:07 PM
Dennis
Dennis - avatar
0
oh..ok tq for the answer
4th Apr 2020, 6:49 PM
durian
durian - avatar