Below are the 2 ways of initialisation in constructor and every way works fine which made me think why each one them is needed and during which situations we could just pick one when others fail.
Does it make any substantial difference ?
Way 1
class myvector
{
public:
myvector();
~myvector();
myvector(int s) : elem{ new double[s] },sz{s} {std::cout << "Hi";}
private:
double *elem;
int sz;
};
other way
class myvector
{
public:
myvector();
~myvector();
myvector(int s) : elem ( new double[s] ),sz (s) {std::cout << "Hi";}
private:
double *elem;
int sz;
};
Aucun commentaire:
Enregistrer un commentaire