0

I'm starting learn constructors and destructors in C++ and I saw it

Vector(const Vector& V) {x=V.x;y=V.y;}

and

Vector(const Vector& V) : x(V.x), y(V.y) {}

But I can't understand what is the second one, this

Vector(const Vector& V) {x=V.x; y=V.y;}

that I suppose equals to

Vector(const Vector& V) {
    x = V.x;
    y = V.y;
}

But what is the other one equals?

Danny_ds
  • 11,201
  • 1
  • 24
  • 46
  • i know that first is constructor without initializing and second with it –  Apr 25 '20 at 12:08
  • 1
    `Vector(const Vector&V):x(V.x),y(V.y){}` is a copy constructor, which initializes the x and y member variables. `Vector(const Vector&V) {x=V.x;y=V.y;}` is a copy constructor, which looks like it does not initialize the x and y member variables (unless they have default initializations), and then assigns values to them. In general, initializing the member variables is recommended, rather than assigning. With optimizations enabled, they're probably the same (but **profile** to make sure). – Eljay Apr 25 '20 at 12:10
  • https://en.cppreference.com/w/cpp/language/initializer_list – Jarod42 Apr 25 '20 at 12:11
  • Where are you learning about constructors that hasn't told you what the second one means? It cannot be a good tutorial. – john Apr 25 '20 at 12:48

0 Answers0