|
From: Alvin T. <alv...@th...> - 2004-09-04 13:30:30
|
Siva Chandra wrote:
> Now I would like to include this header file in
> another header file, header2.h. Here again I want to
> declare a class ClassB under the same namespace abc.
> This ClassB is inherited from ClassA. So to avoid
> writing abc::ClassA everywhere I just say:
>
> using namespace abc;
>
> at the begining of the file. My file would be like:
>
> #ifndef __HEADER2_H__
> #define __HEADER2_H__
>
> #include "header1.h"
>
> using namespace abc;
>
> namespace abc
> { // Start of namespace brace.
>
> class ClassB : public ClassA
> {
> ...
> };
>
> } // End of namespace brace.
>
> #endif // __HEADER2_H__
>
> My question is here: By explicitly putting a statement
> like
>
> using namespace abc;
>
> I am including such a statement in all my code which
> use this header file header2.h. Is there a way to
> avoid such a thing from happening without losing the
> functionality I want it to be there for? Or is it that
> I am not using it in the right manner?
simply drop the 'using namespace abc;' statement. you have no reason to
use it in your example. anything in the 'namespace abc {' block
automatically uses the namespace.
-alvin
|