[LC++]couple of questions (was: Re: testing)
Mark Phillips
mark at austrics.com.au
Wed Oct 31 10:48:50 UTC 2001
Davide Bolcioni wrote:
>
> This is a (hopefully transitory) peculiarity of gcc, and might depend
> on your code using #include <vector.h> rather than #include <vector>,
I do the latter.
> but standard library names should be in std:: and not in the global
> namespace. Namespaces are not "visible", names inside namespaces
> are; a using directive brings names from another namespace into the
> scope it appears in, and there is no way to my knowledge of telling
> which using directives apply to the current scope (except by direct
> inspection, which is much easier if the scope is textually short).
>
> > 2. I would have thought "this[i].foo()" would mean the same as
> > "((*this)[i]).foo()", but it seems it doesn't (at least, according
> > to my gcc compiler). It seems to mean "this.foo()" which to me is
> > crazy. Can anyone explain!
>
> Since "this" is a pointer, "this[i]" is equivalent to "(this + i)",
> indexing into an array of instances starting off at "(this + 0)", which
> might explain what you get. If you meant to call an operator[] defined
> for the class, "*this" is syntactically correct but redundant since the
> operator if called directly applies to the current instance.
Thanks for the explanation.
Cheers,
Mark.
More information about the tuxCPProgramming
mailing list