trying to make a template, but I have an error in gcc4 but not in VS2008. This is the code that fails:
#pragma once
#ifndef _ZELESTE_ZEL_GPX_GENERALMANAGER_H_
#define _ZELESTE_ZEL_GPX_GENERALMANAGER_H_
#include "../internal/cuCoreLib.h"
#include "boost/functional/hash.hpp"
#include "boost/ptr_container/ptr_map.hpp"
namespace z3d{
namespace core{
template<class Key, class Value>
class cuManager
{
boost::ptr_map<Key, Value> m_ItemMap;
public:
/**
* Default constructor
*/
cuManager(void){}
/**
* Get a vector that contain the keys of the elements contained in the manager.
* @return an const std::vector of type Key
*/
const std::vector<Key> g开发者_运维百科etKeys()
{
boost::ptr_map<Key,Value>::iterator itr = m_ItemMap.begin();
std::vector<Key> v;
while(itr != m_ItemMap.end())
{
v.push_back(itr->first);
++itr;
}
return v;
}
}
};
};
This is one of the methods that fails to compile (all methods of the class fail in the same iterator). This code works fine into visual studio but compilation in GCC return this error:
/home/dev001/desarrollo/code/lpgameengine/LPGameEngine/src/core/datatypes/cuManager.h: In member function ‘const std::vector<_Tp, std::allocator<_CharT> > z3d::core::cuManager<Key, Value>::getKeys()’:
/home/dev001/desarrollo/code/lpgameengine/LPGameEngine/src/core/datatypes/cuManager.h:28: error: expected ‘;’ before ‘itr’
/home/dev001/desarrollo/code/lpgameengine/LPGameEngine/src/core/datatypes/cuManager.h:30: error: ‘itr’ was not declared in this scope
Any help will be welcome
Declare it like this:
typename boost::ptr_map<Key,Value>::iterator itr = m_ItemMap.begin();
^^^^^^^^
The point is that boost::ptr_map<Key,Value>::iterator
is a dependent name, so you have to specify that it's a type name (and not a variable name or a template name).
精彩评论