易截截图软件、单文件、免安装、纯绿色、仅160KB

关于linux与windows stl map的问题

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;


相关问答:

linux gcc OCI 编译问题

在linux下,怎样编译OCI的程序?它的gcc指令是什么?我从网上找的都不能用!还有,我在linux用C与oracle连接,我都需要安装oralce的哪些软件?只需要oralce的客户端,与OCI的库么?别的还需要么?
请高手指教! ......

Linux小问题

Linux不正常关机导致系统坏,请问怎么检查和修复系统?
在刚启动的时候会有提示的。

修复可以靠livecd
或者把基本系统部分重新安装即可

是不是系统编程了read-only的啦?无法往系统写入数据啊?
有的情 ......

linux初学者请教linux C++编程学习

windows 下的C++编程比较熟练。现在需要转入linux下。

  我用的软件是  Source Insight和 SecureCRT , 远程连接 linux服务器。 

  由于我的 Liunx基础为0. 就是说以前从来都没 ......

请问有没有全中文的linux系统?

我用过ubuntu8.10版本,从verycd下载的。

下载后,是半英文。且我对linux系统的操作理解不深,因此装中文输入法都搞了好久。

然后按照网上的教程更新中文界面,但是更新了1晚上后提示中断……雷。
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号