首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

template 内嵌类作为当前模板类参数,该怎么解决

2012-05-13 
template 内嵌类作为当前模板类参数template typename T class allocate{public:allocate(){}~allocat

template 内嵌类作为当前模板类参数
template < typename T > class allocate
{
public:
allocate(){}
~allocate(){}
public:
T* alloc() { return new T; }
  ....
};

template < typename T, allocate< typename ta_class<T>::tag_unit > *_pal > class ta_class
{
public:
typedef struct tag_unit
{
T _ocore;
}unit, *lp_unit;
private:
allocate< unit > *_palloc;
public:
  ta_class() { _palloc = _pal; }
.......
};

初学模板,想实现这种模板类内部的类作为自身模板类参数.但是编译过不去,求帮助

[解决办法]
不要这么玩了。ta_class<T>在里面就是一个未知的类型。
[解决办法]
A类当中私有数据成员是B类的对象
然后实现这样一个模板,B类对象的类型决定A类对象的类型??
[解决办法]
模板不是那样用的,你可以以下面的模子为起点,看看能不能达到你的目的。

C/C++ code
template <typename t> class allocate{ public: ~allocate () { }  allocate () { } public:  t* alloc () { return new t; }};template < typename t, template <typename> class alloc = allocate>class ta_class{ struct tag_unit { }; private : alloc<tag_unit> m_alloc;};int main (){ ta_class<int> test; return 0;}
[解决办法]
讨厌模板,现在看着就蛋疼了。。

热点排行