template variables in function calls

This is a discussion on template variables in function calls within the C++ Programming forums, part of the General Programming Boards category; Hi, I know that templates are precompile commands but still I was wondering if there is a way to use ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    11

    template variables in function calls

    Hi, I know that templates are precompile commands but still I was wondering if there is a way to use template class variables ( pointers or something ) in function calls without having to provide the template arguments?

    Somenthing like this:

    Code:
    template< int S >
    class foo
    {
    protected:
        int size = S;
    ...
    };
    
    class bar
    {
    protected:
        foo< 20 > abc;
    public:
        void      Set_Data( foo* def )
        {
              if( abc.size < def->size )
              {
                   do_something_...
              }
        }
    
        foo*     Get_Data()
        {
             return &abc;
        }
    ...
    };

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    No. The template parameters are part of the type. You can't omit them. Except for one case: a class template may omit them when referring to its own, current instantiation.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. 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
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  5. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM

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