Solved

Template in template

Posted on 2002-04-08
3
265 Views
Last Modified: 2010-04-02
Hi, I've run into a Visual C++ 6.0 compiler problem, that I'm not able to workaround anymore.

Using STL, an example of the problem is having a vector of lists:

std::vector<std::list<int>>

That's too much for the compiler. My easy workaround was to do a typedef std::list<int> IntList, and then compile:

std::vector<IntList>

However, I'm now making my code more general using templates. So the int in the example has turned into SomeType:

template<class SomeType>
[...]
std::vector<std::list<SomeType>>

and now my typedef trick doesn't work anymore...

How do I solve this problem? Or who knows a workaround that honors the generalization purpose (obviously I don't want to make implementations for each of the SomeType types)?

TIA
0
Comment
Question by:vendrig
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 6925583
Make it read

std::vector<std::list<int>

Note the blank. The compiler misinterprets that as the ">>" operator.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6925592
BTW - this behaviour is called the "Max Munch" principle, see also http://www.gotw.ca/gotw/078.htm ("Who Is Max Munch, and What's He Doing In My C++ Compiler?"), where your problem  is described in detail...
0
 
LVL 2

Author Comment

by:vendrig
ID: 6925626
Thank you for your quick response:-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object modeling - load and save functions 5 62
Printing the elements of a set declared inside a map in C++. 3 52
C++ Code Issue 4 25
Gaming Software 1 19
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question