fork download
  1. #include <iostream>
  2.  
  3. template <typename T, typename FT>
  4. void test( const FT & (T::*ptr)() const )
  5. {
  6. std::cout << "const exists" << std::endl;
  7. }
  8.  
  9. template <typename T, typename FT>
  10. void test( FT & (T::*ptr)() )
  11. {
  12. std::cout << "non-const exists" << std::endl;
  13. }
  14.  
  15.  
  16. struct A {
  17. const double & a() const { return a_; }
  18. double & a() { return a_; }
  19.  
  20. private:
  21. double a_;
  22. };
  23.  
  24. struct B {
  25. const double & b() const { return b_; }
  26.  
  27. private:
  28. double b_;
  29. };
  30.  
  31.  
  32.  
  33. int main( int argc, char **argv )
  34. {
  35. test(&A::a);
  36. test(&B::b);
  37.  
  38. return 0;
  39. }
  40.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:35: error: call of overloaded ‘test(<unresolved overloaded function type>)’ is ambiguous
prog.cpp:4: note: candidates are: void test(const FT& (T::*)()const) [with T = A, FT = double]
prog.cpp:10: note:                 void test(FT& (T::*)()) [with T = A, FT = double]
stdout
Standard output is empty