I need to call a function from the declaration type on some object outside the class. I made a small code example and set the desired behavior as comments, since I don’t know exactly how to set this :)
template<typename T> void hun(T* obj, class C* c) { //do some checking on c if(some conditions from c are true) { //call fun from T ignoring it virtual } } struct A { virtual void fun(){}; virtual void gun(class C* c) { //do something specific to A hun(this, c); //here call fun from A even if real type of this is B }; } struct B : public A { void fun(){}; void gun(class C* c) { //do something specific to B hun(this, c);//here call fun from B even if real type of this is something derived from B }; }
Is it possible to achieve this behavior?
I know that I can call fun() from within the class using A::fun() or B::fun() , but the check from hun() is common to all classes, and I don't want to pollute gun() this code .
source share