Click here to Skip to main content
13,086,265 members (73,227 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 20 Feb 2010

Emulation of CRuntimeClass for non-CObject derived classes

, 20 Feb 2010
Rate this:
Please Sign up or sign in to vote.
MACROs having advantage of CRuntimeClass for non-CObject derived classes.


Let's assume you decided to create a hierarchy of non-CObject derived classes using the CRuntimeClass of MFC libraries (and DECLARE_DYNAMIC IMPLEMENT_DYNAMIC DECLARE_DYNCREATE IMPLEMENT_DYNCREATE as well). It is implied that your base class is named like CXxx (C + class prefix) and all your child classes have names according to the rule: C+ class prefix + kind_name (for example, CXxxCool, CXxxAdvanced, CXxxSuper etc.). You need to have a static function Create(string kind_name) to create objects at runtime and a function GetKind returning a string with a 'kind_name' of the object.


Unlike CRuntimeClass (actually it is a structure), our 'CKindOf...' class exists as MACROs DECLARE_KIND_OF(class_name) and IMPLIMENT_KIND_OF(class_name), and every generated 'KindOf' class corresponds with a given class hierarchy.



Using the code

The base class of your hierarchy should use the DECLARE_BASE_DYNCLASS(class_name) and IMPLIMENT_BASE_DYNCLASS(class_name) MACROs.

class CXyz




And every child class should use DECLARE_CHILD_DYNCLASS(class_name,kind_name) and IMPLIMENT_CHILD_DYNCLASS(class_name,kind_name,parent_name).

class CXyzCool:public CXyz


class CXyzAdv:public CXyzCool


If your child class is derived directly from the base class (the second level in the class hierarchy), use the 'Base' keyword as the third argument.


And the prefix of the base class otherwise:



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Elstab
Uzbekistan Uzbekistan
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralDerived class name for non-CObject derived classes Pin
geoyar23-Feb-10 7:29
membergeoyar23-Feb-10 7:29 
GeneralRe: Derived class name for non-CObject derived classes Pin
Rishat Bekmukhamedov23-Feb-10 19:26
memberRishat Bekmukhamedov23-Feb-10 19:26 
GeneralRe: Derived class name for non-CObject derived classes Pin
geoyar25-Feb-10 4:31
membergeoyar25-Feb-10 4:31 
GeneralRe: Derived class name for non-CObject derived classes Pin
Rishat Bekmukhamedov26-Feb-10 2:02
memberRishat Bekmukhamedov26-Feb-10 2:02 
GeneralSome Explaination Pin
JohnWallis4221-Feb-10 10:11
memberJohnWallis4221-Feb-10 10:11 
GeneralRe: Some Explaination [modified] Pin
Rishat Bekmukhamedov21-Feb-10 16:41
memberRishat Bekmukhamedov21-Feb-10 16:41 
GeneralRe: Some Explaination Pin
JohnWallis4221-Feb-10 17:11
memberJohnWallis4221-Feb-10 17:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170813.1 | Last Updated 21 Feb 2010
Article Copyright 2010 by cyberanarchist
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid