What is the most appropriate way to initialize members of a class using a constructor in C++? Most video tutorials describe the second approach, while I tried the following way and it works fine.
class node
{
public:
int x, y;
node( int a, int b ) { x = a; y = b;}
};
And this apporach is commonly used in tutorials or books:
class node {
public:
int x, y;
node(int a, int b): x(a), y(b) {}
};
I find the first approach more intuitive.