473,403 Members | 2,284 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,403 software developers and data experts.

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


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

Similar topics

0
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
16
by: horacius.rex | last post by:
Hi, I don't know if it is better to post this question to a C or C++ group, so my apologies. My general question: I have a very big C++ program (Main.cpp) which compiles on machine X with...
9
by: deedub65 | last post by:
I am getting a "Missing ) after argument list" on two different sets of commands in the same script - they are part of Dreamweaver MX's files, so i am not sure how they got altered - thanks for the...
2
by: raj | last post by:
Hi all, I'm using this code to import some a .txt files onto a webpage, but I keep seeing single quotes amd double quotes as question marks. Here's the code: <textarea disabled="disabled"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.