我有一个使用库B的库A.我希望A的用户使用B库中的模板化类。但是A和B有不同的命名空间,是否可以在A命名空间中封装/隐藏B中的那个类?
我尝试使用PIMPL但是......它是一个模板,所以我不知道我该怎么做。
作为参考,我想要封装在我的库中的类是:
namespace anax {
template <typename T>
class Component : public BaseComponent
{
public:
static detail::TypeId GetTypeId()
{
return detail::ClassTypeId<BaseComponent>::GetTypeId<T>();
}
};
}
所以A的用户必须这样做:
class Position: public anax::Component<Position>
{
float x,y,z;
}
我要问的是,是否可以在我的命名空间中封装/隐藏此anax :: Component类,如下所示:
class Position: public myAnamespace::Component<Position>
{
float x,y,z;
}
答案 0 :(得分:3)
怎么样:
namespace myAnamespace{
template<class Position>
using Component = anax::Component<Position>;
}
或者,在前C ++ 11中,
namespace myAnamespace{
template<class Position>
struct Component
{
typedef anax::Component<Position> type;
};
}
答案 1 :(得分:1)
namespace anax
{
class Component
{
};
};
namespace b
{
using namespace anax;
class Position : public Component
{
};
};