-3

if i have an object of class c1 suppose its name object1 and i want to make another object of the same class suppose object2 is it better to declare it like this:

c1 object2 = object1;

or use the copy constructor

c1 object2 = c1(object1);

i now that in C# it differs because in the first case it copies the reference of the object and in the second case it creates a new one, but i want to now if it is the same in c++

basel man
  • 471
  • 1
  • 5
  • 10

1 Answers1

1

The two forms will do exactely the same thing (copy the object). It makes no difference.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • 2
    This is not strictly correct, prior to c++17. The first one only calls the copy constructor, the second calls the copy constructor and then the move constructor. – Nir Friedman Jun 04 '17 at 15:59