最近在学二叉树时突然想把结构体模板和typedef一起使用,但是编译器给我报错了
代码我是这么写的
template <typename T>
typedef struct _Bnode{
int element;
_Bnode<T> * lChild, * rChild;
}Bnode,*Btree;
运行结果及报错内容
有谁知道这是为什么吗😥
template <typename T>
typedef struct _Bnode{
int element;
_Bnode<T> * lChild, * rChild;
}Bnode,*Btree;
有谁知道这是为什么吗😥
typedef
不能给模板起别名,但是你可以用C++11的using
给模板起别名。
template <typename T>
struct _Bnode
{
int element;
_Bnode<T> *lChild, *rChild;
};
template <typename T>
using Bnode = _Bnode<T>;
template <typename T>
using Btree = _Bnode<T> *;