A
A
Hi,
It is recommened by many practitioners to always use an initialisation list
to initialise data members of a class. However, I am having problems with
such a list when passing parameters/arguments to a constructor of a class -
see code below:
class Foo{
int number;
public:
Foo(int number): this->number(number) {}
};
The problem lies with the this pointer and the fact that the arguments that
is passed has the same name as a data member of the class. Of course if i
renamed the argument and thus avoid the need of the this pointer the problem
will go away. However, is there a solution to this if i cannot avoid
changing the name of the argument?
Any help appreciated
Regards,
A
It is recommened by many practitioners to always use an initialisation list
to initialise data members of a class. However, I am having problems with
such a list when passing parameters/arguments to a constructor of a class -
see code below:
class Foo{
int number;
public:
Foo(int number): this->number(number) {}
};
The problem lies with the this pointer and the fact that the arguments that
is passed has the same name as a data member of the class. Of course if i
renamed the argument and thus avoid the need of the this pointer the problem
will go away. However, is there a solution to this if i cannot avoid
changing the name of the argument?
Any help appreciated
Regards,
A