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

Template question: list<Bar<double>> ...

P: n/a

Hi

I have a class Foo that I use both as a Foo<doubleand a Foo<float>. I
want to put instances of this class in a list container. The list
container itself is a template and need a type argument. The naive way
below does not work.

list<Bar<double>myList;

It produces the error message: Error: "," expected instead of ">>". How
do I solve this problem?
Thanks in advance, Daniel

Sep 18 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
jan...@gmail.com wrote:
Hi

I have a class Foo that I use both as a Foo<doubleand a Foo<float>.
Those are two _different_ classes, instantiated from the same class
template.
I want to put instances of this class in a list container.
Since they are two different classes, you can't put both in a single
list container without resorting to some tricks that probably would
make this more complicated than it ought to be.
The list
container itself is a template and need a type argument. The naive way
below does not work.

list<Bar<double>myList;
Change the above line to:

std::list<Bardouble myList; // note space between the two ">"
It produces the error message: Error: "," expected instead of ">>". How
do I solve this problem?
Well, that will solve _one_ of your problems.

Best regards,

Tom

Sep 18 '06 #2

P: n/a
list<Bar<double>myList;
>
It produces the error message: Error: "," expected instead of ">>". How
do I solve this problem?
The lexer is reading >as one token. You need to put a space between
them:
list<Bar<double myList;

Michael

Sep 18 '06 #3

P: n/a
Thomas Tutone wrote:
list<Bar<double>myList;

Change the above line to:

std::list<Bardouble myList; // note space between the two ">"
Sorry, typo. Should be:

std::list<Bar<double myList; // note space between the two ">"

Best regards,

Tom

Sep 18 '06 #4

P: n/a
The list
container itself is a template and need a type argument. The naive way
below does not work.

list<Bar<double>myList;

Change the above line to:

std::list<Bardouble myList; // note space between the two ">"
Adding the missing '<' it works perfectly. So one need to add a space
not to confuse the compiler? I mean, so it doesn't think you want to
use the >stream operator.
It produces the error message: Error: "," expected instead of ">>". How
do I solve this problem?

Well, that will solve _one_ of your problems.
Well, the other is quite similar :)

Sep 18 '06 #5

P: n/a
ja****@gmail.com wrote:
>
I have a class Foo that I use both as a Foo<doubleand a Foo<float>.
You have a template named Foo, from which you create two classes,
Foo<doubleand Foo<float>.
I
want to put instances of this class in a list container. The list
container itself is a template and need a type argument. The naive way
below does not work.

list<Bar<double>myList;

It produces the error message: Error: "," expected instead of ">>". How
do I solve this problem?
typedef Foo<doubledescriptive_name;
list<descriptive_namemyList;

or:

list< Foo<double myList;

or wait for a C++0x compiler, which will be available sometime in the
next ten years, and will accept:

list<Foo<double>myList;

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Sep 18 '06 #6

P: n/a
ja****@gmail.com wrote:
The list
container itself is a template and need a type argument. The naive way
below does not work.

list<Bar<double>myList;

Change the above line to:

std::list<Bardouble myList; // note space between the two ">"

Adding the missing '<' it works perfectly. So one need to add a space
not to confuse the compiler? I mean, so it doesn't think you want to
use the >stream operator.
As of now, yes. Usually, when it requires it, I will also add an extra
space at the beginning for symmetry:

std::list< Bar<double myList;

IIRC, this will be fixed in C++0x.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Sep 18 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.