template help

This is a discussion on template help within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm reading about template. And here's a bit of code that I don't understand. It's a code for a ...

  1. #1
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455

    template help

    Hi,
    I'm reading about template. And here's a bit of code that I don't understand. It's a code for a stack.

    Code:
    template <class Type>
    class Stack
    {
    private:
      enum{SIZE = 10};
      int stack_size;
      Type * items;
      int top;
       .
       .
       .
    and in main, it would say:
    Code:
    Stack<const char*> st;

    If I pass "const char *" into the template, would that make "items" type "char **"?
    "All that we see or seem
    Is but a dream within a dream." - Poe

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That should make items of type "const char **".

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    To be fair, it would make items of type const char*. That's what you push and pop. The internal representation of that stack if using a pointer to that type, const char*, so yes, it would be const char**.
    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.

  4. #4
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    455
    thank you guys for the quick reply. I got it now.
    "All that we see or seem
    Is but a dream within a dream." - Poe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment issues
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 01-13-2010, 11:55 AM
  2. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

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