templates - Determine class type in C++ without reflection/introspection -


i have interface class called , 2 base classes b , c implement a. in code need determine if instance either b or c , prefer not have local non-static member of determines if implementing class of type b or c. performance reasons not use dynamic_cast or other forms of reflection determine type.

would advisable make base class aa takes template argument of type int , use value determine type of b or c?

or how defining static method in returns enum type shadowed similar methods in b , c?

are trying avoid virtual functions in general? in case, can add functionality itself:

struct {     enum classtype { classtypeb, classtypec };     const classtype mclasstype;      classtype classtype() const     { return mclasstype; }  protected:     a(classtype type) : mclasstype(type) { } }; 

in child classes initialize like:

struct b: public {     b() : a(classtypeb) { } };  struct c: public {     c() : a(classtypec) { } };  // ...  a* obj1 = new b; a* obj2 = new c; obj1->classtype() == a::classtypeb; // true obj2->classtype() == a::classtypec; // true 

this lets avoid virtual method dispatch, drawback a must have knowledge of child classes.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -