In this case one may use the native .NET containers instead, but what if
I want a vector of Buttons? The .NET STL versions have definitions that
take managed types under consideration (handles ^ and tracking
references %) and also inherit from the aforementioned interfaces for
interoperability with the other languages.
I don't know what these 'managed' types and 'handles' are, but they
aren't C++. They may be in some proprietary language but that is
off-topic in comp.lang.c++. I know nothing of .NET and have no interest
either, the next language I'm learning will be Java because it's likely
to be required in my job...
For example instead of returning an IList ^ explicitly by making the
necessary conversions or using it since the beginning, one C++
programmer can just return a stdcli::vector<int> ^ and the C# fellow can
use it as a IList ^.
In which case it gets an error because IList ^ is invalid C++. C# is
also off-topic in comp.lang.c++.
The bottom line is we have a system-dependent .NET vector version and
the std::vector. Also one may want (and even nowadays use) a third party
native C++ library like Boost with a function or method that returns
an std::vector, together with managed code, in mixed mode (in fact I
guess all C++ programmers in .NET work that way, myself for example
prefer to use std::wstring instead of System::StringBuilder today), so
as to have and utilise all C++ facilities out there.
So you need to distinguish them, and the only way to do that is to use
the std:: or stdcli:: or whatever prefixes to at least one of the types.
The same applies just as much whether you have used using namespace at
file scope or function scope, if you need to mix them then you need to
disambiguate specific cases.
And stdcli::vector is a different type from std::vector, since it
inherits from these interfaces and thus not implicitly interchangeable
between them (perhaps stdcli::vector may have an assignment operator and
copy constructor taking std::vector, I do not know, but this does not
change things), so we have two types named vector inside the same code.
Yup. One is named std::vector and the other is named stdcli::vector.
What's the problem?
If things were simpler we would not have namespaces after all.
There are plenty of simpler situations for which namespaces are useful.
One major one is having multi-module libraries with shared identifiers
which are 'global' (in the sense of being visible to the linker) but
which are not visible to the user, without having to do explicit name
prefixes (mylib_func1(), mylib_func2() etc. gets clumsy, much easier for
each module to reside in namespace mylib and call them whatever the
implementor likes). The anonymous namescape also removes the need for
the horribly overloaded 'static' keyword by providing a file scope
namespace.
Well, you prefer this approach, I prefer another. We have got in a habit
issue here and I do not think we can reach an agreement.
If you mean it's a style issue, perhaps it largely is, which is my
point, there is nothing intrinsically better about your style because it
can run into exactly the same problems.
It is like void foo() {
vs void foo
{
The latter is not valid C++, if you want to define a function you must
have at least an empty pair of parentheses.
In any case I am bored to type std::vector all the time.
If you are mixing two namespaces with vector in each then you have to
disambiguate it somehow. Or just don't use broken proprietary libraries
which have identifiers which look like ones in namespace std but act
differently.
I too don't like typing std:: all over the place, which is why I
generally do using namespace std; at file scope at the top...
Chris C