Solved

Template in template

Posted on 2002-04-08
3
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

728 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