By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,442 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,442 IT Pros & Developers. It's quick & easy.

Iterators with unresolved template parameters

P: n/a
Porting a project from VC8 to GCC, I stumbled on this:

I have certain templates that use STL collections with a
value type that is a pointer to a template parameter type.
When I declare iterators for these parametrized collections,
GCC chokes.

template class MapWrapper<T{
std::map<MyKey, T*myMap; // OK with both compilers
myMethod(){
std::map<MyKey, T*>::iterator i; // GCC chokes
}
}
Did I get the syntax wrong, or is GCC buggy here?

I circumvented it by using B* as the map value type,
where B is a common base class for the T classes used,
combined with unchecked (C-style) casts - but this isn't
supposed to be necessary when working with templates.
Dec 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Ole Nielsby wrote:
Porting a project from VC8 to GCC, I stumbled on this:

I have certain templates that use STL collections with a
value type that is a pointer to a template parameter type.
When I declare iterators for these parametrized collections,
GCC chokes.

template class MapWrapper<T{
std::map<MyKey, T*myMap; // OK with both compilers
myMethod(){
std::map<MyKey, T*>::iterator i; // GCC chokes
}
}
Did I get the syntax wrong, or is GCC buggy here?
Nope, its doing its job. the map iterator is a dependent type.

#include <map>

template< typename Key, typename T >
class Map {
std::map< Key, T*m_map;
void myMethod() {
typedef typename std::map< Key, T*>::iterator Miter; // dependent
type
MIter miter = m_map.begin();
}
};
>
I circumvented it by using B* as the map value type,
where B is a common base class for the T classes used,
combined with unchecked (C-style) casts - but this isn't
supposed to be necessary when working with templates.
Dec 27 '06 #2

P: n/a
Salt_Peter <pj*****@yahoo.comwrote:
>
Ole Nielsby wrote:
>Porting a project from VC8 to GCC, I stumbled on this:

template class MapWrapper<T{
std::map<MyKey, T*myMap; // OK with both compilers
myMethod(){
std::map<MyKey, T*>::iterator i; // GCC chokes
}
}
Did I get the syntax wrong, or is GCC buggy here?

Nope, its doing its job. the map iterator is a dependent type.

#include <map>

template< typename Key, typename T >
class Map {
std::map< Key, T*m_map;
void myMethod() {
typedef typename std::map< Key, T*>::iterator Miter; // dependent
type
MIter miter = m_map.begin();
}
};
Thanks - seems I forgot the 'typename' keyword in the original
version, and VC8 didn't require it.
Dec 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.