类型转换模板

Atu*_*tul 0 c++ templates

我试图制作一个类型转换的模板,我在编译以下程序时遇到错误.

#include<iostream.h>
#include<conio.h>
template<typename T,typename U>
T mycast(U u)
{
 return (T)u;
}
int main()
{
 double d= 10.6577;
 int j= mycast<int>(d) ;
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

请告诉我哪里有问题以及如何克服?谢谢

Oli*_*rth 5

如果我删除#include <iostream.h>(因为它应该是#include <iostream>,但它不需要它),那么它编译得很好(在VS 2010中).

  • @Atul:它是预标准的编译器.请立即更新. (5认同)
  • @Atul:然后切换到更好(和更新)的编译器. (3认同)