Sometimes I write constructor code like
class X
{
public:
X( const int numberOfThingsToDo ) :
numberOfThingsToDo( numberOfThingsToDo )
{
}
private:
int numberOfThingsToDo;
};
or in C#
class X
{
public X( int numberOfThingsToDo )
{
this.numberOfThingsToDo = numberOfThingsToDo;
}
private int numberOfThingsToDo;
}
I think the main reason is that when I come up with a suitable member name, I see no reason to use a different one for the argument initializing it, and since I'm also no fan of using underscores the easiest is just to pick the same name. After all it's suitable.
Is this considered bad practice however? Any drawbacks (apart from shooting yourself in the foot when forgetting the this
in C#)?
-Wall
." So what does "all" mean if it doesn't mean "all"? It means (quoting again) "all the warnings about constructions that some users consider questionable ..." (whatever that means). It doesn't mean-Wextra
,-Wold-style-cast
,-Woverloaded-virtual
, or-Wshadow
, for example. There are quite a few other warnings that-Wall
does not catch. – David Hammen Oct 08 '12 at 21:22-Weverything
, which is an LLVM (clang, clang++, ...) option. Even the LLVM developers don't recommend that ordinary developers use-Weverything
. Too many false positives. – David Hammen May 06 '14 at 22:09