typedef in templates?
-
I'm writing a class which is more or less a STL map with a few enhancements, e.g. sending of update notifications. To still have STL like access to the map, I forward the map iterators in my class with public typedefs. The problem is, those typedefs seem to be missing a semicolon where there is definitely none missing;
#include template class Repository { private: typedef std::map ReposMap; public: typedef ReposMap::iterator iterator; //line 14 typedef ReposMap::const_iterator const_iterator; //line 15 public: Repository() { } ~Repository() { } //[...] some other functions ... private: ReposMap m_objects; };
MSVC8 gives the following error msgs compiling this code:Error 2: error C2146: syntax error : missing ';' before identifier 'iterator' 14
Error 3: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 14and the same error msgs again for line 15 before 'const_iterator' I was wondering what the error could be in that few lines of code. Typedefs should be able to work with template parameters, so there shouldn't be an problem, should it? I'm trying to compile this and some other versions of the same problem for two days now, but I don't have an idea, what could cause the problem, so I'd appreciate any suggestions. thanks in advance, Norbert
-
I'm writing a class which is more or less a STL map with a few enhancements, e.g. sending of update notifications. To still have STL like access to the map, I forward the map iterators in my class with public typedefs. The problem is, those typedefs seem to be missing a semicolon where there is definitely none missing;
#include template class Repository { private: typedef std::map ReposMap; public: typedef ReposMap::iterator iterator; //line 14 typedef ReposMap::const_iterator const_iterator; //line 15 public: Repository() { } ~Repository() { } //[...] some other functions ... private: ReposMap m_objects; };
MSVC8 gives the following error msgs compiling this code:Error 2: error C2146: syntax error : missing ';' before identifier 'iterator' 14
Error 3: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 14and the same error msgs again for line 15 before 'const_iterator' I was wondering what the error could be in that few lines of code. Typedefs should be able to work with template parameters, so there shouldn't be an problem, should it? I'm trying to compile this and some other versions of the same problem for two days now, but I don't have an idea, what could cause the problem, so I'd appreciate any suggestions. thanks in advance, Norbert
sorry, it seems my <'s have been removed. Here should be the corrected version of the code:
template <typename K, typename V> class Repository { private: typedef std::map<K, V> ReposMap; public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator; public: Repository() { } ~Repository() { } private: ReposMap m_objects; };
-
sorry, it seems my <'s have been removed. Here should be the corrected version of the code:
template <typename K, typename V> class Repository { private: typedef std::map<K, V> ReposMap; public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator; public: Repository() { } ~Repository() { } private: ReposMap m_objects; };
N-O-R-B-E-R-T wrote:
public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator;
Modify this to,
typename ReposMap::iterator iterator;
typename ReposMap::const_iterator const_iterator;See
MSDN
documentation for warningC4346
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
N-O-R-B-E-R-T wrote:
public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator;
Modify this to,
typename ReposMap::iterator iterator;
typename ReposMap::const_iterator const_iterator;See
MSDN
documentation for warningC4346
.Prasad Notifier using ATL | Operator new[],delete[][^]
I've had the warnings supressed, and I forgot about that. I'm sorry for posting without reading all errors AND warnings before. Thanks for your fast help. Norbert
-
I've had the warnings supressed, and I forgot about that. I'm sorry for posting without reading all errors AND warnings before. Thanks for your fast help. Norbert
N-O-R-B-E-R-T wrote:
I've had the warnings supressed, and I forgot about that
You should not ignore warning at all ! :)
Prasad Notifier using ATL | Operator new[],delete[][^]
-
N-O-R-B-E-R-T wrote:
public: typedef ReposMap::iterator iterator; typedef ReposMap::const_iterator const_iterator;
Modify this to,
typename ReposMap::iterator iterator;
typename ReposMap::const_iterator const_iterator;See
MSDN
documentation for warningC4346
.Prasad Notifier using ATL | Operator new[],delete[][^]
prasad_som wrote:
Modify this to, typename ReposMap::iterator iterator;typename ReposMap::const_iterator const_iterator;
I assume you mean this:
typedef typename ReposMap::iterator iterator;
typedef typename ReposMap::const_iterator const_iterator;Steve
-
prasad_som wrote:
Modify this to, typename ReposMap::iterator iterator;typename ReposMap::const_iterator const_iterator;
I assume you mean this:
typedef typename ReposMap::iterator iterator;
typedef typename ReposMap::const_iterator const_iterator;Steve
Stephen Hewitt wrote:
I assume you mean this: typedef typename ReposMap::iterator iterator;typedef typename ReposMap::const_iterator const_iterator;
Yes. :)
Prasad Notifier using ATL | Operator new[],delete[][^]
-
I've had the warnings supressed, and I forgot about that. I'm sorry for posting without reading all errors AND warnings before. Thanks for your fast help. Norbert
Have a look at reply below, posted by Stephan.
Prasad Notifier using ATL | Operator new[],delete[][^]