【发布时间】:2012-08-29 02:16:50
【问题描述】:
为什么以下不会产生编译器错误?
template<typename T>
const T testFunc()
{
return T();
}
float* ptr = testFunc<float*>(); // ptr is not const - should be a compiler error!
在这个例子中,testFunc() 应该返回一个常量 float*,所以当我尝试将它分配给一个非常量 float* 时不应该出现编译器错误吗?
【问题讨论】:
标签: c++ templates pointers constants