use*_*734 4 c++ templates turbo-c++
这个:
非类型模板参数必须是标量类型
是我尝试使用Turbo C++ 4.5构建此程序时得到的错误.我有一些错误,如:
非类型模板参数是指没有链接的函数
但这个错误对我来说是全新的.代码有什么问题?
#include<iostream.h>
template<class T1=int,class T2=int>
class tempex
{
T1 a;
T2 b;
public:
tempex(T1 x,T2 y)
{
a=x;
b=y;
}
void show()
{
cout<<"A= \t"<<a<<"\tB=\t"<<b;
}
};
int main()
{
tempex <float,int> te1(1.23,123);
te1.show();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你似乎在使用一个古老的编译器.尝试使用现代的免费软件,例如VC++ 2013 Express Edition.您将收到更合适的错误消息:
fatal error C1083: Cannot open include file: 'iostream.h' :
No such file or directory
Run Code Online (Sandbox Code Playgroud)
当您通过更改<iostream.h>
为修复此问题时<iostream>
,您将获得:
error C2065: 'cout' : undeclared identifier
Run Code Online (Sandbox Code Playgroud)
如果您通过更改cout
为修复此问题,std::cout
代码将只使用一个警告进行编译:
warning C4305: 'argument' : truncation from 'double' to 'float'
Run Code Online (Sandbox Code Playgroud)
这是通过改为1.23
来解决的1.23f
.
开始了.一个完整的,现代的C++程序.
Turbo C++ 4.5从1994年开始!直到1998年,C++甚至都没有标准化.那么,你的过时的软件无法解析这个[几乎]有效的C++程序,这一点也不足为奇.
1994年还发生了什么?嗯,让我们看看:
你真的应该使用本世纪的东西,比如GCC 4.9或Microsoft Visual Studio 2013; 你也可以使用"旧"之类的编译GCC 4.1或Visual Studio 2005,它仍然是一个十年比你捞出恐龙更年轻.你甚至在哪里找到它?!