3年C++经验看不明白的C++模板,摘自gnash项目
3年C++经验看不明白的C++模板,摘自gnash项目
在gnash 0.8.5源码目录的libbase/tree.hh文件里有如下代码:
1 template <class T, class tree_node_allocator>
2 template <class iter>
3 iter tree<T, tree_node_allocator>::insert_after(iter position, const T& x)
4 {
5 tree_node* tmp = alloc_.allocate(1,0);
6 kp::constructor(&tmp->data, x);
7 tmp->first_child=0;
8 tmp->last_child=0;
9
10 tmp->parent=position.node->parent;
11 tmp->prev_sibling=position.node;
12 tmp->next_sibling=position.node->next_sibling;
13 position.node->next_sibling=tmp;
14
15 if(tmp->next_sibling==0) {
16 if(tmp->parent) // when inserting nodes at the head, there is no parent
17 tmp->parent->last_child=tmp;
18 }
19 else {
20 tmp->next_sibling->prev_sibling=tmp;
21 }
22 return tmp;
23 }
把第1、2两行合并为template <class T, class tree_node_allocator, class iter>,Ubuntu 8.04 + gcc 4.2.4编译报错。
哪位大侠能解释下第1、2两行的具体含义?为什么不能合并为一个template?谢谢!