Thread: Inheriting from specific templated version of 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
    Registered User
    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, 03:04 AM
  3. templated class in multiple files
    By linucksrox in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2006, 06:37 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM