C++ C+的别名+;模板?

C++ C+的别名+;模板?,c++,templates,typedef,C++,Templates,Typedef,其思想是,如果我想在boost interprocess的几个不同的共享内存和分配器选项之间切换,我只需修改typedef。不幸的是,分配器是模板,所以我不能定义我想要使用的分配器 有没有一种方法可以在C++中实现模板的别名?(除了明显的#define ALLOCATOR\u T boost::interprocess::adaptive\u pool)C++不支持此功能,尽管它将在新标准中修复。如果没有非平凡的构造函数(或者如果您很乐意编写一些转发构造函数),那么您可以从adaptive\u

其思想是,如果我想在boost interprocess的几个不同的共享内存和分配器选项之间切换,我只需修改typedef。不幸的是,分配器是模板,所以我不能定义我想要使用的分配器


<>有没有一种方法可以在C++中实现模板的别名?(除了明显的
#define ALLOCATOR\u T boost::interprocess::adaptive\u pool
)C++不支持此功能,尽管它将在新标准中修复。如果没有非平凡的构造函数(或者如果您很乐意编写一些转发构造函数),那么您可以从
adaptive\u pool
派生一个新的类模板

模板
类分配器\u t:公共自适应\u池{
公众:
//作为一个例子,我只是构建了一个转发构造函数。我什么都不知道
//关于游泳池的任何事情。
分配器(int arg1,float arg2):自适应池(arg1,arg2){
};
编辑:忘记这个答案。我的投票结果是@Akanksh。

是的,(如果我正确理解了你的问题),你可以将模板“包装”成如下结构:

template <class T>
class allocator_t : public adaptive_pool<T> {
public:
    // Just making up a forwarding constructor as an example. I know nothing
    // anything about adaptive_pool.
    allocator_t(int arg1, float arg2) : adaptive_pool<T>(arg1, arg2) { }
};
可能是

typedef boost::interprocess::adaptive_pool allocator_t;
模板
结构分配器
{
typedef boost::进程间::自适应_池类型;
}
用作

template<typename T>
struct allocator_t
{
    typedef boost::interprocess::adaptive_pool<T> type;
}
allocator\u t::type

从另一个类派生类模板时会遇到一个问题,即它会变成不同的类型,因此任何采用基类的函数都无法工作。通过将类名包装到结构中,类型保持不变,就像typedef一样,也就是说,它是完全相同的类型。谢谢!包装方法成功了。我无法使用-std=C++0x使C++0x示例在GCC4.4.1中工作<代码>模板类型def boost::进程间::自适应池分配器给出
错误:模板声明'typedef'
MyTypeDef<T>::type
template<typename T>
using MyType = SomeClass<T>;
typedef boost::interprocess::adaptive_pool allocator_t;
template<typename T>
struct allocator_t
{
    typedef boost::interprocess::adaptive_pool<T> type;
}
allocator_t<SomeClass>::type