Templates in C++

This is a discussion on Templates in C++ within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, as the title states I have a question about templates definitions. I have defined a Stack<T> class and ...

  1. #1
    gcc -Wall -pedantic *.c
    Join Date
    Jan 2009
    Location
    London
    Posts
    60

    Templates in C++

    Hi everyone,
    as the title states I have a question about templates definitions. I have defined a Stack<T> class and a BinaryTree<T> class and both work fine, in fact I can have stacks (or trees) of integers, doubles or any other object. However, if I declare a stack of trees of pointer to characters as follows:
    Code:
    Stack<BinaryTree<char*>> stack;
    I get a compiling error regarding the templates definition. I thought this worked as for Java, where that statement would be fine since the tree and the stack classes supported generic objects, but I suppose I had it wrong! What am I missing?.. Am I obliged to define the stack template differently?

    Cheers

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by flexo87 View Post
    Code:
    Stack<BinaryTree<char*>> stack;
    Put a space amidst >>.
    (This bug is not there for C++11 supporting compilers.)

    Also... there may be other problems if you relied upon implicit comparator functions or operators and didn't provide those for the present 'T' .
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    gcc -Wall -pedantic *.c
    Join Date
    Jan 2009
    Location
    London
    Posts
    60
    Quote Originally Posted by manasij7479 View Post
    Also... there may be other problems if you relied upon implicit comparator functions or operators and didn't provide those for the present 'T' .
    Thanks, I will take that into account!

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,556
    Quote Originally Posted by manasij7479 View Post
    (This bug is not there for C++11 supporting compilers.)
    This is not a bug. Rather, it is a missing feature. The standard does not specify that compilers must interpret >> differently depending on context to simplify compilers.
    It is now standardized in C++11 that >> will be interpreted differently depending on context (for example, shifting a number of a template declaration).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with templates
    By hanniball in forum C++ Programming
    Replies: 1
    Last Post: 12-26-2007, 05:16 PM
  2. About Templates
    By mike_g in forum C++ Programming
    Replies: 5
    Last Post: 09-13-2007, 02:56 AM
  3. Templates
    By creativeinspira in forum C++ Programming
    Replies: 7
    Last Post: 08-07-2007, 11:04 PM
  4. using templates
    By Benzakhar in forum Windows Programming
    Replies: 9
    Last Post: 11-24-2003, 05:53 PM
  5. Templates ........
    By Moni in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2002, 03:34 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21