Inheriting from specific templated version of class

This is a discussion on Inheriting from specific templated version of class within the C++ Programming forums, part of the General Programming Boards category; I would like to do something like the following: Code: template<class T> class BaseClass { public: BaseClass(void); //.... } template<class ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    22

    Inheriting from specific templated version of class

    I would like to do something like the following:
    Code:
    template<class T>
    class BaseClass
    {
    public:   
       BaseClass(void);
       //....
    }
    
    template<class T> BaseClass<T>::BaseClass(void)
    {
       //....
    }
    
    
    class SubClass : public BaseClass<SomeType>
    {
    pubic:   
       SubClass(void);
       //....
    }
    
    SubClass::SubClass(void)
    {
       //...
    }
    Using MSVC++ 7, everything compiles fine, but I am getting unresolved external symbol errors from the linker for each function in SubClass stating that a definition in BaseClass is missing. For example, the constructor gives the error
    Code:
    unresolved external symbol: BaseClass<SomeType>::BaseClass<SomeType>(void)
    The generic function definitions are there. This seems to imply that I need to supply specific definitions to be able to inherit this way. Am I doing something wrong? Surely a class structure like this is possible, isn't it?

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    I've had the same problem before, simply put the implementation in the same file. ( .h )

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    22
    For the curious, tilex is correct, the implementation must go in the same file. I think that this is a Visual Studio problem and I believe that this is why: MSDN Knowledge Base

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Most C++ compilers have this problem.
    The only compiler I know of that has implemented the 'export' keyword is Comeau C++.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Look at this thread

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. storing pointers to a templated class in a vector
    By rt454 in forum C++ Programming
    Replies: 4
    Last Post: 01-19-2009, 02:04 AM
  3. templated class in multiple files
    By linucksrox in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2006, 05:37 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 04:06 PM

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