fork download
  1. #include <iostream>
  2.  
  3. template<typename T>
  4. struct Outer
  5. {
  6. private:
  7. void foo()
  8. {
  9. std::cout << "Outer<T>::foo()" << std::endl;
  10. }
  11.  
  12. public:
  13. Outer() : inner( *this , &Outer::foo )
  14. {
  15. inner();
  16. }
  17.  
  18. struct Inner
  19. {
  20. typedef void (Outer<T>::*F)();
  21.  
  22. Inner( Outer<T>& o , F f ) : outer( o ) , func( f )
  23. {
  24. }
  25.  
  26. void operator()()
  27. {
  28. (outer.*func)();
  29. }
  30.  
  31. F func;
  32. Outer<T>& outer;
  33. };
  34.  
  35. Inner inner;
  36. };
  37.  
  38. int main()
  39. {
  40. Outer<int> outer;
  41. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Outer<T>::foo()