这个模板声明有什么问题

What is wrong with this template declaration?

本文关键字:什么 问题 声明      更新时间:2023-10-16
template<class T> void Insert(T*, T) { *T = T; }

产生错误

"T: illegal use of this type as an expression"

此函数模板的主体尝试取消引用并分配类型 T 。这是不可能的,您需要将其更改为

template<class T> void insert(T* t1, T t2)
{
    *t1 = t2;
}