fork download
  1. #include <iostream>
  2.  
  3. template<typename T, int (T::*M)>
  4. int getValue(T const& obj)
  5. {
  6. return obj.*M;
  7. }
  8.  
  9. class NotPlainOldDataType
  10. {
  11. public:
  12. explicit NotPlainOldDataType(int xx) : x(xx) { }
  13. ~NotPlainOldDataType() { }
  14. int x;
  15. };
  16.  
  17. int main()
  18. {
  19. typedef NotPlainOldDataType NPOD;
  20.  
  21. NPOD obj(3);
  22. std::cout << getValue<NPOD, &NPOD::x>(obj) << '\n';
  23. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
3