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