fork download
  1. class FncPtrBase {
  2. public:
  3. virtual ~FncPtrBase() {}
  4. virtual int Get()=0;
  5. virtual float Get()=0;
  6. virtual int Set(int)=0;
  7. virtual float Set(float)=0;
  8. }
  9. // class template for actual data entries
  10. template<class U,typename V>
  11. class FncPtr {
  12. V CallGet() {return (U.*Get)();}
  13. V CallSet(V x) {return (U.*Set)(x);}
  14. };
  15. template<class U,typename V>
  16. class FncPtr:FncPtrBase {
  17. U& Cls; // Reference to object that function will be called on
  18. V (U::*Get)(); // Member function pointers
  19. V (U::*Set)(V);
  20. public:
  21. FncPtr(U& cls,V (U::*get)(), V (U::*set)(V)):Cls(cls),Get(get),Set(set);
  22. int Get() {}
  23. float Get() {}
  24. int Set(int i) {}
  25. float Set(float f){}
  26. }
  27. //*** Class Specializations *********
  28. template<class U>
  29. class FncPtr:FncPtrBase {
  30. U& Cls; // Reference to object that function will be called on
  31. float (U::*Get)(); // Member function pointers
  32. float (U::*Set)(float);
  33. public:
  34. FncPtr(U& cls,float (U::*get)(), float (U::*set)(float))
  35. :Cls(cls),Get(get),Set(set);
  36. int Get() {}
  37. float Get() {U.*Get();}
  38. int Set(int i) {}
  39. float Set(float f) {U.*Set(f);}
  40. }
  41. template<class U>
  42. class FncPtr:FncPtrBase {
  43. U& Cls; // Reference to object that function will be called on
  44. int (U::*Get)(); // Member function pointers
  45. int (U::*Set)(int);
  46. public:
  47. FncPtr(U& cls,int (U::*get)(), int (U::*set)(int))
  48. :Cls(cls),Get(get),Set(set);
  49. int Get() {U.*Get();}
  50. float Get() {}
  51. int Set(int i) {U.*Set(i);}
  52. float Set(float f) {}
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:16: error: ‘virtual float FncPtrBase::Get()’ cannot be overloaded with ‘virtual int FncPtrBase::Get()’
  virtual float Get()=0;
                ^~~
prog.cpp:4:15: note: previous declaration ‘virtual int FncPtrBase::Get()’
  virtual int  Get()=0;
               ^~~
prog.cpp:8:3: error: expected ‘;’ after class definition
  }
   ^
   ;
prog.cpp: In member function ‘V FncPtr<U, V>::CallGet()’:
prog.cpp:12:31: error: expected primary-expression before ‘.*’ token
     V CallGet()     {return (U.*Get)();}
                               ^~
prog.cpp:12:33: error: ‘Get’ was not declared in this scope
     V CallGet()     {return (U.*Get)();}
                                 ^~~
prog.cpp: In member function ‘V FncPtr<U, V>::CallSet(V)’:
prog.cpp:13:31: error: expected primary-expression before ‘.*’ token
     V CallSet(V x)  {return (U.*Set)(x);}
                               ^~
prog.cpp:13:33: error: ‘Set’ was not declared in this scope
     V CallSet(V x)  {return (U.*Set)(x);}
                                 ^~~
prog.cpp: At global scope:
prog.cpp:16:7: error: redefinition of ‘class FncPtr<U, V>’
 class FncPtr:FncPtrBase {
       ^~~~~~
prog.cpp:11:7: note: previous definition of ‘class FncPtr<U, V>’
 class FncPtr    {
       ^~~~~~
prog.cpp:42:7: error: redeclared with 1 template parameter
 class FncPtr:FncPtrBase {
       ^~~~~~
prog.cpp:11:7: note: previous declaration ‘template<class U, class V> class FncPtr’ used 2 template parameters
 class FncPtr    {
       ^~~~~~
stdout
Standard output is empty