how do I derive a class from a template class?
-
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
-
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
-
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
-
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)
-
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.
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.
-
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)
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 {}).
-
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 {}).
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)
-
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)
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 { };
-
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)