templatizing a derived class

This is a discussion on templatizing a derived class within the C++ Programming forums, part of the General Programming Boards category; is it possible to templatize a derived class? supposed i have class A, using the type string. but i want ...

  1. #1
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455

    templatizing a derived class

    is it possible to templatize a derived class?

    supposed i have class A, using the type string.

    but i want to derive class B from class A, but templatizing it. supposed i wanted to use some of class A's functions...does the type passed have to be casted to type string?

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    I'm not sure what you are asking, but here are a few examples that might help:

    Code:
    // Legal
    class A
    {
    };
    
    template<typename T>
    class B : public A
    {
    };
    
    // Legal
    template<typename T>
    class A
    {
    };
    
    class B : public A<std::string>
    {
    };
    
    // Legal
    template<typename S>
    class A
    {
    };
    
    template<typename T>
    class B : public A<T>
    {
    };
    
    // NOT Legal
    template<typename T>
    class A
    {
    };
    
    class B : public A
    {
    };
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    thanks..why is the last one not legal? if ia class is templated all of its derivates have to also be templated?

    wait nevermind, you have give it a type. that answered my question (bascially the 3rd example)
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. call base class function or derived class function
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 06:23 AM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 12:36 PM
  3. derived class can not access base class protected member?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2007, 07:32 PM
  4. Replies: 4
    Last Post: 12-29-2002, 12:29 AM
  5. Constructors + Derived class
    By MethodMan in forum C++ Programming
    Replies: 6
    Last Post: 11-10-2002, 05:05 PM

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