This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

namespaces composition and selection


Hi,

 Here is the sample program I have written :

------------------------------------------------------------
 #include "user_defined.h"
                                                                                
 //using namespace user_defined;
                                                                                
int main()
 {
 user_defined::base *b=new user_defined::base();
 b->display();
                                                                                
 user_defined::base *y = new user_defined::base();
 y->display();
 }
 ---------------------------------------------------------

 file : user_defined.h

 #include "mine.h"
 #include "yours.h"
                                                                                
namespace user_defined {
                                                                                
 using namespace mine; //use all from mine
 using namespace yours; //use all from yours
                                                                                
 using yours::base;   //resolve conflict for base in favour of yours
 };

-------------------------------------------------------------

 Both mine::base and yours::base exists.(base is again another class)
 and as commented yours::base is favoured when there is a conflict.

 The problem I encountered is, I cannot directly use any decalaration 
 related to base without scope resolution(user_defined::base).

 What I want is : Can I not make it work with 
          using namespace  user_defined;  
 alone(the part has been commented ).If comments are removed and scope 
 resolution is also removed, the compiler complaines of ambigous base 
 class type.
 
 Can somebody pull me out?

 [I am trying this example with gcc version 3.2.3 20030502.The example
 is related to c++ Programming language by Stroustrup]

  Thanks in advance.   
 


-- 
Regards,
Anitha B.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]