c++ - Creating a namespace using a class defined in another namespace -
i trying out following code whether works or not. need whether done in other way.
// foo.hpp namespace traits { class foo { public: typedef std::vector<int> vec_t; typedef std::map <int, int> map_t; }; }; namespace my_traits = traits::foo; //i know compile give error "foo" not namespace-name. // in bar.hpp using namespace my_traits; class bar { private: vec_t my_vector; // my_traits have foo's members (typedefs) map_t my_map; // my_traits have foo's members (typedefs) }; **don't** want following : using namespace traits; class bar { private: traits::foo::vec_t my_vector // avoid traits::foo::map_t my_map // avoid }
but want put typedefs in class foo , use foo namespace. dont want put typdefs in namespace such.
is possible in c++11 (or in general c++).
thanks
you cannot use class
namespace
, have use real namespace
:
namespace traits { namespace foo { typedef std::vector<int> vec_t; typedef std::map <int, int> map_t; }; }; namespace my_traits = traits::foo;
using namespace my_traits; class bar { private: vec_t my_vector; // my_traits have foo's members (typedefs) map_t my_map; // my_traits have foo's members (typedefs) };
Comments
Post a Comment