Share this post

Link to post

Share on other sites

"the compiler will generate the default constructor if you don't define it"

This should read "the compiler will generate the default constructor if you don't define any constructor". Otherwise you will need to specify one. Generally this is not a real problem - as you're surely aware, initializer lists are your friends.

Quote:

Original post by DeyjaHowever, it might also fail because of this: i(i). If that works, it's still extremely poor style.

It does work (because the scoping rules are different inside and outside the brackets), and there's nothing wrong with it; I've seen it endorsed implicitly by many prominent users around here (including myself).

Share on other sites

Original post by DeyjaHowever, it might also fail because of this: i(i). If that works, it's still extremely poor style.

It does work (because the scoping rules are different inside and outside the brackets), and there's nothing wrong with it; I've seen it endorsed implicitly by many prominent users around here (including myself).

Agreed, and as a fact I use this method all the time.

The variables named in an initializer list as being initialized must come from the class itself, so the outer i is allways the class member, in this case the integer listed right after the private: label. You can't do:

int unrelated;

struct foo { foo( int pie ) : unrelated( pie ) { }}

Similarly, the i supplied in the constructor's argument list will shadow the member variable as per normal scoping rules. This means that the inner i is allways the argument. It's good style, it's defined behavior by the standard, and it's sexy good. Or something.

Share on other sites

I've seen it endorsed implicitly by many prominent users around here (including myself).

I haven't; nor would I call you prominent.

And I suppose you are? :-).

Quote:

Quote:

It's good style, it's defined behavior by the standard, and it's sexy good. Or something.

It's disgusting mental ambiquity and belongs with the same camp that uses 1 as a variable name. Hint for those who don't see the problem: That's a 1, not an l.

Dosn't seem ambiguous to me, mental or otherwise. You construct i from the value i, and then i == i, no mater what Is you're talking about. Instead of arguing this point with someone who obviously has no hands on experience with this practice (as evidenced by thinking that this could be causing compiler errors), I'd rather switch topics and point out:

There are instances where 1 has been used as a variable name. Usually slightly decorated, since in most languages you simply cannot use 1 in and of itself as a variable name - it won't let you. But people try to get as close as possible anyways: Boost.Lambda, part of the wonderful C++ library collection that aims and does help set existing practice to be used in molding the future of the C++ standard, uses "_1". Apache, the industry standard HTTP server, has Rule Rewriters using $1 (see example config).

And how much do they really differ? After all, 1 is just a "const int" assigned to some random binary, _1 just a "boost::lambda::placeholder1_type", and $1 is simply a "string".

Interesting, got any references for those styles? i(i_) in particular is very strange.

m_i( i ) is usually proported by the same people that recommend m_ prefixes for all member variables. It goes hand in hand with that naming style for obvious reasons... it's similar to your use of i_( i ), but of older vintage AFAIK.

References:1) The standard library implementation on my computer uses _M_i, as an underscore followed by a capital letter is reserved for "the implementation".2) Some googling seems to hint this practice stems from the MFC, which uses m_ for members and g_ for globals, etc.

My opinion is that it's an ugly hungarian notation hangover. In the few cases where it isn't obvious or implied that i is a member variable, "this->i" clearly states the fact.

i( i_ ) and i( new_i ) are similar in that they seek to decorate the less commonly used variable to distinguish between what are essentially the same values. There are many other variants, such as i( ii ), i( _i ), i( I ), etc...

No particular reference I have to bring to bear, but I think it's quite silly fluff to add when I type: