c++ - Calling a non-virtual function in derived class using a base class pointer -


as noted in this answer:

high reliance on dynamic_cast indication design has gone wrong.

what i'd know how can call custom function in derived class, there no same-name function in base class, using base class pointer , perhaps without dynamic_cast if in fact there better way.

if function virtual function defined in both, that's easy. unique function in derived class.

perhaps dynamic_cast best way afterall?

in order call function of derived class have obtain pointer derived class. option (depending on situation) may want using static_cast instead of dynamic, said:

it indication design has gone wrong

also, sometimes think it's ok use casts. when designing gui library game has base class widget , lots of subclasses. actual window layout made in editor , later loader class inflating layout. in order fill widgets layout actual specific each widget data (game related) made method quering widget's child widget. function retuned widget* , dynamic_casted actual type. have not found better design this.

later found gui system on android works same way


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -