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

  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,897
    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, 08: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, 05:46 PM
  4. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  5. Operator overloading in template classes
    By moejams in forum C++ Programming
    Replies: 5
    Last Post: 07-21-2003, 05:16 PM