fork download
  1. #include <iostream>
  2.  
  3. class Super {
  4. public: virtual void print() const {
  5. std::cout << __PRETTY_FUNCTION__ << std::endl;
  6. }
  7. public: virtual ~Super() {}
  8. };
  9.  
  10. class Sub : public Super {
  11. public: virtual void print() const {
  12. std::cout << __PRETTY_FUNCTION__ << std::endl;
  13. }
  14. };
  15.  
  16. int main() {
  17. Super *obj = new Sub();
  18. // how to call 'Super::print()' from 'obj'
  19. // without using operator '.' and/or '->'?
  20.  
  21. typedef void (*PFUNC)(void *);
  22. PFUNC pFunc = (PFUNC)&Super::print;
  23. pFunc(obj);
  24.  
  25. delete obj;
  26. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
virtual void Super::print() const