Hallo allen,
Ik zit momenteel even met mijn handen in het haar...
We hebben een VC++ 6.0 project welke we willen bewerken en bouwen vanaf VS2005 (C++). Helaas loop ik hierbij in een vervelend probleem in de hoek van STL mappen. Ik heb geen kaas gegeten van STL (het is 3rd party code), dus ik hoop dat jullie me iets vooruit kunnen helpen.
Eerst hieronder de bewuste code (header-file), die als basis dient voor andere map-classes. Hier gaat de compiler de mist in gaat tijdens compileren. Ik heb de code iets gestript om het overzichtelijk te houden.
Als we een file compileren die deze header-file meeneemt, worden we verrast met de volgende compiler warnings / errors (ik heb de regelnummers ook even kloppend gemaakt met bovenstaande code snippet):
Het gaat uiteindelijk om het eerste stukje: template <typename keyT, typename objT> en de private data members van deze class.
Alvast bedankt en ik hou jullie ook op de hoogte...
Ik zit momenteel even met mijn handen in het haar...
We hebben een VC++ 6.0 project welke we willen bewerken en bouwen vanaf VS2005 (C++). Helaas loop ik hierbij in een vervelend probleem in de hoek van STL mappen. Ik heb geen kaas gegeten van STL (het is 3rd party code), dus ik hoop dat jullie me iets vooruit kunnen helpen.
Eerst hieronder de bewuste code (header-file), die als basis dient voor andere map-classes. Hier gaat de compiler de mist in gaat tijdens compileren. Ik heb de code iets gestript om het overzichtelijk te houden.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
| // ...
// File : SynchronizedMap.h
//
// Description: Encapsulates the functionalities of a synchronized map container of objects.
//
// Decisions
//
// History :
// ....
#ifndef _C_SYNCHRONIZED_MAP_H
#define _C_SYNCHRONIZED_MAP_H
#include "HmpMutex.h"
#include <map>
template <typename keyT, typename objT>
class CSynchronizedMap
{
public:
// ... removed some methods to keep this small
/**
* Function : LookupObject
*
* Abstract : Lookup in the map the object associated with a certain key.
*
* Exception: -
*
* Remarks : If an object was found the return value is true and the rObject is valid.
* If no object is found the return value is false and rObject is invalid.
*/
bool LookupObject ( keyT key, objT& rObject )
{
std::map < keyT, objT >::iterator matchedObject;
bool bFound = false;
if ( m_Mutex.Lock () == true )
{
// check if the map is not empty
if ( !m_ObjectsMap.empty () )
{
// lookup
matchedObject = m_ObjectsMap.find ( key );
if ( matchedObject != m_ObjectsMap.end () )
{
// if the key matched an item get the address of that item
rObject = (*matchedObject).second;
bFound = true;
}
}
m_Mutex.Unlock ();
}
return bFound;
}
// ... removed some methods to keep this small
/**
* Function : HasNext
*
* Abstract : Returns true if there is a next element
* starting from the current position of
* the class iterator
*
* Exception: -
*
* Remarks :
*/
bool HasNext ()
{
bool bResult = false;
if ( m_Mutex.Lock () == true )
{
// If the map is empty then
if ( m_Iterator != m_ObjectsMap.end() )
{
m_Iterator++ ;
if ( m_Iterator != m_ObjectsMap.end ())
{
bResult = true;
}
m_Iterator-- ;
}
m_Mutex.Unlock ();
}
return bResult;
}
/**
* Function : GetNext
*
* Abstract : Returns the object associated with
* the next key from the map, considering
* the current position of the maps' iterator.
*
* Exception: -
*
* Remarks :
*/
bool GetNext ( objT& rObject )
{
bool bResult = false;
if ( m_Mutex.Lock () == true )
{
if ( HasNext () )
{
m_Iterator++;
rObject = ( *m_Iterator ).second;
bResult = true;
}
m_Mutex.Unlock ();
}
return bResult;
}
private:
// The map container. The default sorting criterion used is less.
std::map < keyT, objT > m_ObjectsMap;
// The iterator used to iterate the map
std::map <keyT, objT >::const_iterator m_Iterator;
// Mutex used for syncrhonizing the map
CHmpMutex m_Mutex;
};
#endif // _C_SYNCHRONIZED_MAP_H |
Als we een file compileren die deze header-file meeneemt, worden we verrast met de volgende compiler warnings / errors (ik heb de regelnummers ook even kloppend gemaakt met bovenstaande code snippet):
code:
1
2
3
| Warning 1 warning C4346: 'std::map<keyT,objT>::const_iterator' : dependent name is not a type z:\synchronizedmap.h 128 Error 2 error C2146: syntax error : missing ';' before identifier 'm_Iterator' z:\synchronizedmap.h 128 Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int z:\synchronizedmap.h 128 |
Het gaat uiteindelijk om het eerste stukje: template <typename keyT, typename objT> en de private data members van deze class.
Alvast bedankt en ik hou jullie ook op de hoogte...