can I qualify template types outside of the template class, but still within header

This is a discussion on can I qualify template types outside of the template class, but still within header within the C++ Programming forums, part of the General Programming Boards category; Let's say I have a class Code: template <class T> SomeClass{}; within it I have an operation Code: doSomething(T param); ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    can I qualify template types outside of the template class, but still within header

    Let's say I have a class

    Code:
    template <class T>
    SomeClass{};
    within it I have an operation
    Code:
    doSomething(T param);
    but if the function get's pretty big is there a way to pull it out the actual class declaration but still have it within the header and qualify all the typenames like so

    Code:
    template <class T>
    SomeClass
    {
         public:
             doSomething(T param);
    };
    
    //this is where the actual definition of doSomething goes
    is this at all possible, simply for neatness.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Yes, but it can get rather cryptic because you need to redeclare the template arguments:
    Code:
    template <class T>
    SomeClass {
    public:
      void doSomething(T param);
    };
    
    template <class T>
    void SomeClass<T>::doSomething(T param)
    {
      // Blah blah
    }
    My best code is written with the delete key.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    that's cool.

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I'm getting errors like, "request for member `push' in `aStack', which is of non-class type `Stack<int> ()()'"

    when I try to use it with a parameter. I've already declared the Stack class with the template parameter of the same type I'm trying to use the member function for.

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    bah, I guess you aren't supposed to initialize a template class using the parenthesis if the constructor has no parameters.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 09:44 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. help with template class using a template node
    By aciarlillo in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2005, 06:46 PM
  4. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-24-2004, 12:22 AM
  5. Operator overloading in template classes
    By moejams in forum C++ Programming
    Replies: 5
    Last Post: 07-21-2003, 06:16 PM

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