문제

I want to detect if a function was (statically) overridden in a derived class:

template< typename T >
struct A{ void func(){ static_cast<T*>(this)->func(); } };
struct B: A<B>{};
struct C: A<C>{ void func(){  std::cout << "class C" << std::endl;  };

C c;
if(&A<C>::func != &C::func)
  c.func();

Obviously, I won't call 'func' if it has no override. I prefer direct answers to my questions. Telling about the actual problem to determine the overloading. I will also appreciate any answer that shows other ways to approach the general problem.

Ok, it compiles, I have yet to find the difference to my actual code, that didn't. By the way, in my actual code, I am not just trying to avoid calling the function, there is some more. I really want to know if the function is overridden, or if I need to use a completely different method.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top