Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how do I derive a class from a template class?

how do I derive a class from a template class?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Klaus Petersen
    wrote on last edited by
    #1

    Hi I am having trouble trying to derive one class from a template class. I keep getting the following error when I try to derive the class CFlashText from the class CFlash. error C2059: syntax error : ',' My code code looks like this: Header file: class CFlashText : public CText, public CFlash< CFlashText > { public: CFlashText(); virtual ~CFlashText(); }; cpp file: CFlashText::CFlashText() : CText, CFlash< CFlashText > //<-- it is in this line the compiler gives me the error { } CFlashText::~CFlashText() { } Does anyone know why this error appears? Klaus Petersen

    L N 2 Replies Last reply
    0
    • K Klaus Petersen

      Hi I am having trouble trying to derive one class from a template class. I keep getting the following error when I try to derive the class CFlashText from the class CFlash. error C2059: syntax error : ',' My code code looks like this: Header file: class CFlashText : public CText, public CFlash< CFlashText > { public: CFlashText(); virtual ~CFlashText(); }; cpp file: CFlashText::CFlashText() : CText, CFlash< CFlashText > //<-- it is in this line the compiler gives me the error { } CFlashText::~CFlashText() { } Does anyone know why this error appears? Klaus Petersen

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      cpp file: CFlashText::CFlashText(): CText, CFlash< CFlashText > { } Why are u doing this? Why not just use the second constructor?? Any const members? Papa Murex Co.

      K 1 Reply Last reply
      0
      • K Klaus Petersen

        Hi I am having trouble trying to derive one class from a template class. I keep getting the following error when I try to derive the class CFlashText from the class CFlash. error C2059: syntax error : ',' My code code looks like this: Header file: class CFlashText : public CText, public CFlash< CFlashText > { public: CFlashText(); virtual ~CFlashText(); }; cpp file: CFlashText::CFlashText() : CText, CFlash< CFlashText > //<-- it is in this line the compiler gives me the error { } CFlashText::~CFlashText() { } Does anyone know why this error appears? Klaus Petersen

        N Offline
        N Offline
        Niklas L
        wrote on last edited by
        #3

        You'll need : CText**()**, CFlash<CFlashText>**()**

        K 1 Reply Last reply
        0
        • N Niklas L

          You'll need : CText**()**, CFlash<CFlashText>**()**

          K Offline
          K Offline
          Klaus Petersen
          wrote on last edited by
          #4

          Wups I forgot the () after the constructors Thank you for helping me out. The program compiles now The only problem is that now it shows a linker error. Linker errors: FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ) FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash::~CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)

          N 1 Reply Last reply
          0
          • L Lost User

            cpp file: CFlashText::CFlashText(): CText, CFlash< CFlashText > { } Why are u doing this? Why not just use the second constructor?? Any const members? Papa Murex Co.

            K Offline
            K Offline
            Klaus Petersen
            wrote on last edited by
            #5

            CFlashText is an text object that has the ability to flash an object. It gets the flash specific methods from CFlash and the text specific methods from CText. CFlash flashes an object by calling draw and erase methods in the object it is flashing (here CText). To do this it needs to know the type of the object it is flashing. To make CFlash useable on other objects than CText I want to implement CFlash as a template. Hereby giving it the ability to flash another object if desired.

            1 Reply Last reply
            0
            • K Klaus Petersen

              Wups I forgot the () after the constructors Thank you for helping me out. The program compiles now The only problem is that now it shows a linker error. Linker errors: FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ) FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash::~CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)

              N Offline
              N Offline
              Niklas L
              wrote on last edited by
              #6

              Klaus Petersen wrote: FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ) FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash:CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ) tells you there are no implementations for the constructor and destructor of CFlash. If you explicitly declare them, you'll need to implement them aswell (with at least empty {}).

              K 1 Reply Last reply
              0
              • N Niklas L

                Klaus Petersen wrote: FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ) FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash:CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ) tells you there are no implementations for the constructor and destructor of CFlash. If you explicitly declare them, you'll need to implement them aswell (with at least empty {}).

                K Offline
                K Offline
                Klaus Petersen
                wrote on last edited by
                #7

                The implementation is done in the cpp file, as usual. It doesn't seem to work but I can't see there is anything wrong with the code. My code looks like this: header file: #if !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_) #define AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_ #include "Text.h" #include "Flash.h" #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CFlashText : public CText, public CFlash< CFlashText > { public: CFlashText(); virtual ~CFlashText(); }; #endif // !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_) cpp file //implementation #include "stdafx.h" #include "FlashText.h" CFlashText::CFlashText() : CText(), CFlash< CFlashText >() { } CFlashText::~CFlashText() { } does anyone know why this code doesn't work??? The linker gives the following linker error on the code: FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ) FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash::~CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)

                C N 2 Replies Last reply
                0
                • K Klaus Petersen

                  The implementation is done in the cpp file, as usual. It doesn't seem to work but I can't see there is anything wrong with the code. My code looks like this: header file: #if !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_) #define AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_ #include "Text.h" #include "Flash.h" #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CFlashText : public CText, public CFlash< CFlashText > { public: CFlashText(); virtual ~CFlashText(); }; #endif // !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_) cpp file //implementation #include "stdafx.h" #include "FlashText.h" CFlashText::CFlashText() : CText(), CFlash< CFlashText >() { } CFlashText::~CFlashText() { } does anyone know why this code doesn't work??? The linker gives the following linker error on the code: FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ) FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash::~CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)

                  C Offline
                  C Offline
                  Chad Koehler
                  wrote on last edited by
                  #8

                  hmmm....I don't know if there is anything wrong with what you are trying to do. My only thought would be that the CFlash is relying on the constructor of CFlash and for some reason, it is not accpeting that. FYI, this is how we do it. template class foo_template { }; class foo { }; class foo2 : public foo_template { };

                  1 Reply Last reply
                  0
                  • K Klaus Petersen

                    The implementation is done in the cpp file, as usual. It doesn't seem to work but I can't see there is anything wrong with the code. My code looks like this: header file: #if !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_) #define AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_ #include "Text.h" #include "Flash.h" #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CFlashText : public CText, public CFlash< CFlashText > { public: CFlashText(); virtual ~CFlashText(); }; #endif // !defined(AFX_FLASHTEXT_H__50B175B8_B909_4161_BDB7_B4960ECF9B0E__INCLUDED_) cpp file //implementation #include "stdafx.h" #include "FlashText.h" CFlashText::CFlashText() : CText(), CFlash< CFlashText >() { } CFlashText::~CFlashText() { } does anyone know why this code doesn't work??? The linker gives the following linker error on the code: FlashText.obj : error LNK2001: unresolved external symbol "public: __thiscall CFlash::CFlash(void)" (??0?$CFlash@VCFlashText@@@@QAE@XZ) FlashText.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CFlash::~CFlash(void)" (??1?$CFlash@VCFlashText@@@@UAE@XZ)

                    N Offline
                    N Offline
                    Niklas L
                    wrote on last edited by
                    #9

                    It's not CFlashText that is the problem, it's CFlash that is missing its constructor and destructor, just as the linker messages states. You will need CFlash::CFlash() {} and CFlash:: ~CFlash() {} somewhere.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups