The obvious advantage of namespaces is that they avoid name conflicts. However, by introducing the full namespace into the class declaration, this advantage is invalidated. It is possible that a function in the System namespace may conflict with your own Bar :: MemberFunc function. You even noticed this in your code example when you added the comment "there is no conflict with this."
Obviously, you do not want to introduce integer namespaces into your class as follows:
using namespace System; using namespace System::Network; using namespace System::Network::Win32::Sockets;
And you cannot add narrower scopes with such statements to the class declaration. Entering them directly into a class declaration is illegal.
using System::Network::Win32::Sockets::Handle; using System::Network::Win32::Sockets::Error;
What you can do is use an unnamed namespace. So your header file will look something like this:
namespace { using System::Network::Win32::Sockets::Handle; using System::Network::Win32::Sockets::Error; } class Foo : public Bar { using Bar::MemberFunc;
This has three distinct advantages.
- The contents of whole namespaces are not entered. This helps to avoid name conflicts more easily.
- You have a list before declaring a class that your class depends on the proper operation.
- Your feature ads are clean.
Please correct me if I am wrong; I just checked it out briefly. Quickly wrote an example and it compiled.
Ichimonji10 Dec 06 '10 at 5:36
source share