[LC++]couple of questions (was: Re: testing)
9odb6x3rfr001 at sneakemail.com
Wed Oct 31 08:54:42 UTC 2001
Mark Phillips mark at austrics.com.au [mltuxcpp/linux-cpp list] wrote:
> David Lloyd wrote:
> Yes, it has been a bit quiet.
> Just to liven things up a bit, here's a couple of things I have
> been wondering about:
> 1. Does the STL "vector" sit inside the "std" namespace? I thought
> it did, yet I seem to be able to access it without dereferencing with
> "std". Either it doesn't use it, or perhaps I accidentally do a
> "using namespace std" somewhere. I don't think I do though. Is there
> anyway of telling what namespaces are visible at a certain point in
> the code?
This is a (hopefully transitory) peculiarity of gcc, and might depend
on your code using #include <vector.h> rather than #include <vector>,
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.
There is no place like /home.
More information about the tuxCPProgramming