H
Henrik Goldman
Using std::map I'm creating a class which adds a thread safety layer on top
of map.
However on some compilers I receive compiler errors which are not easily
decipherable.
I'm pretty sure that it's not a compiler specific problem but rather a lack
of understaning on my part of how to do the deriving correctly.
Here is the short version of the problem:
#include <map>
using namespace std;
template <class T, class U>
class CMap
{
public:
virtual ~CMap() {}
typedef typename map<T,U>::value_type value_type;
typedef typename map<T,U>::iterator iterator;
.... omitted code
protected:
map<T, U> m_Map;
};
template <class T, class U>
class CThrSafeMap: public CMap<T, U>
{
public:
virtual iterator Insert(const value_type &V) // <<---- problem is here
{
CMutexGuard MtxGuard(&m_Mutex);
return m_Map.insert(V).first;
}
While it works perfectly fine with Visual Studio I'm receiving errors with
g++ 3.4.6:
.../../shared/generic/mymap.h:51: error: `iterator' does not name a type
.../../shared/generic/mymap.h:51: error: (perhaps `typename CMap<T,
U>::iterator' was intended)
.../../shared/generic/mymap.h: In member function `virtual bool
CThrSafeMap<T, U>::IsEmpty()':
.../../shared/generic/mymap.h:62: error: `m_Map' was not declared in this
scope
What am I missing here?
Should I go further with the typename keyword?
Thanks.
-- Henrik
of map.
However on some compilers I receive compiler errors which are not easily
decipherable.
I'm pretty sure that it's not a compiler specific problem but rather a lack
of understaning on my part of how to do the deriving correctly.
Here is the short version of the problem:
#include <map>
using namespace std;
template <class T, class U>
class CMap
{
public:
virtual ~CMap() {}
typedef typename map<T,U>::value_type value_type;
typedef typename map<T,U>::iterator iterator;
.... omitted code
protected:
map<T, U> m_Map;
};
template <class T, class U>
class CThrSafeMap: public CMap<T, U>
{
public:
virtual iterator Insert(const value_type &V) // <<---- problem is here
{
CMutexGuard MtxGuard(&m_Mutex);
return m_Map.insert(V).first;
}
While it works perfectly fine with Visual Studio I'm receiving errors with
g++ 3.4.6:
.../../shared/generic/mymap.h:51: error: `iterator' does not name a type
.../../shared/generic/mymap.h:51: error: (perhaps `typename CMap<T,
U>::iterator' was intended)
.../../shared/generic/mymap.h: In member function `virtual bool
CThrSafeMap<T, U>::IsEmpty()':
.../../shared/generic/mymap.h:62: error: `m_Map' was not declared in this
scope
What am I missing here?
Should I go further with the typename keyword?
Thanks.
-- Henrik