473,395 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Iterators with unresolved template parameters

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
2 1958

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Old Wolf | last post by:
Hi all. G++ fails to compile the following: #include <string> int main() { std::string foo("abc=123"); std::string::const_iterator delimiter = std::find(foo.begin(), foo.end(), '=');
3
by: YAN KANG / SU | last post by:
Hi, All I am migrating to Studio .NET 2003 from Studio 6.0 and Studio .NET 2002. When I compiled my code, which is compilable both in VC++ 6.0 and Studio .NET 2002, I have an error LNK2019 as the...
19
by: John | last post by:
In STL's map implementation, the distance between two iterators it1, it2 takes O(K) to compute where K is the actual distance between the two iterators. In theory, a red black tree can do this...
2
by: tllee | last post by:
I wrote a simple stack program using class template on VC++ 2003 but am unable to resolve the following link errors: LINK : error LNK2020: unresolved token (0A000046) Stack.__dtor LINK : error...
6
by: Dilip | last post by:
Hi All I have a pure virtual function in my base class that my derived instances override. What are the likely causes for VC++ 7.1 to complain of unresolved external symbol on that pure virtual...
6
by: gexarchakos | last post by:
Hi there, Please give me at least a hint... I have a problem implementing a function object with parameters two iterators. That is: A class 'node' produces messages using a routing policy....
8
by: desktop | last post by:
In accelerated C++ on page 146 there is this example: template <class In, class Out> Out copy(In begin, In end, Out dest) { While (begin != end) *dest++ = *begin++; return dest; }
7
by: JustBeSimple | last post by:
Hi Everyone, I'm having a problem compiling useing the VS2005 .NET I need help to resolve those error, I try to create a new project it doesn't help any suggestion? I got the following errors:...
5
by: jgscott | last post by:
I've been trawling around for an answer to this question and thought I'd try here. I have a class Graph, which has a std::list<Nodeas a class member. Node it itself a class that makes extensive...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.