C++ 带有常量的模板函数参数

C++ 带有常量的模板函数参数,c++,data-structures,C++,Data Structures,我知道参考并不是重点。引用不是对象。因此没有常量引用 const int ci = 1024; const int &rl = ci; 我们无法编写int const&rl=…,但今天,我将学习一个二叉树源代码: template <typename T> //take e as the node insert the left child of the tree. BinNodePosi(T) BinNode<T>::insertAsLC(T const &a

我知道参考并不是重点。引用不是对象。因此没有常量引用

const int ci = 1024;
const int &rl = ci;
我们无法编写
int const&rl=…
,但今天,我将学习一个二叉树源代码:

template <typename T> //take e as the node insert the left child of the tree.
BinNodePosi(T) BinNode<T>::insertAsLC(T const & e) {  return lChild = new BinNode(e, this);  }
template//将e作为节点插入树的左子节点。
BinNodePosi(T)BinNode::insertAsLC(T const&e){return lChild=newbinnode(e,this);}

我对它的参数感到困惑:T const&e。为什么不持续T&e?我认为后者是对的。。也许我的问题太简单了,无法在这里发布。与数学不同,研究级别和研究级别分别有两个方面:MathOverFlow和math.stackexchange。。我找不到stackoverflow的初级站点。。所以我把它贴在这里。请原谅我。非常感谢。

const适用于紧靠其左侧的对象,除非它是类型说明符序列中的第一项,在这种情况下,它适用于下一项

因此,
T常数&e
常数T&e
完全等价。你似乎想到的非法案件是
T&const e
。同样,指向可变对象的不可变指针将被声明为
T*const e

就我个人而言,我避免把
const
放在第一位,因为它是语法的一个特例