Solved

Template in template

Posted on 2002-04-08
3
266 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

685 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