C/C++ code:
#include <map>
using namespace std;
template<typename K, typename T>
class a
{
public:
map<K,T> _map;
T find(K v)
{
map<K,T>::iterator iter;
iter = _map.find(v);
if(iter != _map.end())
return iter->second;
else
return (T)0;
}
};
int main()
{
a<int, unsigned int> b;
return 0;
}
为什么这段代码在vc2005中可以编译通过,而在linux(red heat)下不能通过?
那是因为int和unsigned int在linux平台下没有区别。
模板的二义性。与编译器实现有关。
去掉a <int, unsigned int> b;这行也一样,与模板参数无关
test.cpp: In member function `T a <K, T>::find(K)':
test.cpp:11: error: expected `;' before "iter"
test.cpp:12: error: `iter' was not declared in this scope
red heat下编译报这个错
呃,google 模板参数依赖类型。
typename的功能没好好学吧。
加上 typename.
如下:
#include <map>
using namespace std;
template <typename K, typename T>
class a
{
public:
map <K,T> _map;
T find(K v)
{
typename map <K,T>::iterator iter;
相关问答:
目标:当网络中有数据到达或者超时,程序进入下一次循环。
问题:select()函数不起作用,程序不会在select的地方阻塞一秒,并且当网络上有数据的时候,select的返回值仍然小于0
#include <s ......
大家好,本人目前刚刚接触Linux。现在公司的项目需要缩减Linux的Kernel和APP部分的Code Size。目前我们使用的是Linux2.6.22.15版本,应用于ADSL Modem(家庭网关)。
1.我们产品应用是ADSL Gateway,Kernel部 ......
我没有安装操作系统的经验,即使是WINDOWS。现在想在LINUX操作系统大环境下学C语言,又要买本本,请问如果操作系统安装不当,会不会对电脑造成什么大的破坏?有没有必要先买一个二手电脑练一下LINUX的 ......
使用Struts2上传文件,在linux下报错
2009-09-29 14:56:20,801 [org.apache.struts2.interceptor.FileUploadInterceptor]-[ERROR] Processing of multipart/form-data request failed. c:/temp/upload__1dcd07ee_12 ......
windows 下的C++编程比较熟练。现在需要转入linux下。
我用的软件是 Source Insight和 SecureCRT , 远程连接 linux服务器。
由于我的 Liunx基础为0. 就是说以前从来都没 ......