我有这个源代码,允许我投射Point<float>到Point<double>:
template<class T> struct Point{
template <typename NewType> Point<NewType> cast() const{
return Point<NewType>();
}
};
int main(){
Point<float> p1;
Point<double> p2;
p2 = p1.cast<double>();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个源代码编译得很好.现在,我添加以下类,我在执行转换的行中有一个编译错误:
template <class T> struct PointContainer{
void test(){
Point<T> p1;
Point<double> p2;
p2 = p1.cast<double>(); //compilation error
}
};
Run Code Online (Sandbox Code Playgroud)
编译错误:error: expected primary-expression before ‘double’.
为什么我会收到此错误,如何解决?