Topic: generic types


Author: chiu@snoopy.stdavids.picker.com (Arnold Chiu)
Date: Mon, 29 Nov 1993 17:10:10 GMT
Raw View
I'm trying to do something like:

 List<Cmd<T>> queue;

where List and Cmd are both templates, ListItem is helper
template for List, and T is typically a function pointer.
This got a compiler error.

The alternatives seems to be:

 1) make a class with two lists:
  List<Cmd> cmdQ;
  List<T> funcQ;

 2) subclass T under Cmd

I don't like either solution.  Anyone got better ideas?

Please send email to me directly at chiu@stdavids.picker.com

Thanks,

Arnold.




Author: timms@rchland.vnet.ibm.com (George Timms)
Date: Mon, 29 Nov 1993 23:14:52 GMT
Raw View
In article <CHIU.93Nov29121010@snoopy.stdavids.picker.com>, chiu@snoopy.stdavids.picker.com (Arnold Chiu) writes:
|>
|> I'm trying to do something like:
|>
|>  List<Cmd<T>> queue;
|>
|> where List and Cmd are both templates, ListItem is helper
|> template for List, and T is typically a function pointer.
|> This got a compiler error.

What's the compiler error?  If you programmed it exactly as shown above, the
error is probably because the "maximum munch" rule forces the compiler to
parse >> as a single token.  Try adding a blank between them:

        List< Cmd<T> > queue;

--
 George Timms        timms@vnet.ibm.com
 IBM AS/400 Division
 Rochester, MN  55901




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Tue, 30 Nov 1993 04:05:02 GMT
Raw View
chiu@snoopy.stdavids.picker.com (Arnold Chiu) writes:


>I'm trying to do something like:
>
> List<Cmd<T>> queue;
>
>where List and Cmd are both templates, ListItem is helper
>template for List, and T is typically a function pointer.
>This got a compiler error.

This is a Frequently Asked Question and the problem is mentioned
in the FAQ list for comp.lang.c++.
Use the following instead:
 List<Cmd<T> > queue; // note the extra space !

--
Fergus Henderson                     fjh@munta.cs.mu.OZ.AU




Author: cpf@alchemy.TN.Cornell.EDU (Courtenay Footman)
Date: Tue, 30 Nov 1993 05:14:23 GMT
Raw View
In article <CHIU.93Nov29121010@snoopy.stdavids.picker.com> chiu@snoopy.stdavids.picker.com (Arnold Chiu) writes:
>
>I'm trying to do something like:
>
> List<Cmd<T>> queue;
Try putting a space between the two right angle brackets:
List <Cmd<T> > queue;

Then figure out how your compiler was parsing your first expression,
and you will see why it was giving you an error.


--
-------------------------------------------------------------------------------
Courtenay Footman                       I finally got back on the net.
cpf@alchemy.ithaca.ny.us                Now I will never get anything done