fork download
  1. #include <iostream>
  2.  
  3. class Ptr
  4. {
  5. public:
  6. typedef void (*ptr_type) ();
  7.  
  8. Ptr(const Ptr& value);
  9. Ptr(ptr_type value);
  10.  
  11. ptr_type GetPtr() const;
  12. Ptr& operator=(const Ptr& value);
  13. Ptr& operator=(ptr_type value);
  14.  
  15. private:
  16. ptr_type value_;
  17. };
  18.  
  19. Ptr::Ptr(const Ptr& value) :
  20. value_(value.value_)
  21. {
  22. }
  23.  
  24. Ptr::Ptr(ptr_type value) :
  25. value_(value)
  26. {
  27. }
  28.  
  29. Ptr::ptr_type Ptr::GetPtr() const
  30. {
  31. return value_;
  32. }
  33.  
  34. Ptr& Ptr::operator=(const Ptr& value)
  35. {
  36. value_ = value.value_;
  37. return *this;
  38. }
  39.  
  40. Ptr& Ptr::operator=(ptr_type value)
  41. {
  42. value = value_;
  43. return *this;
  44. }
  45.  
  46. class TestClass
  47. {
  48. public:
  49. TestClass();
  50.  
  51. static void TestFunction();
  52. };
  53.  
  54. TestClass::TestClass()
  55. {
  56. Ptr myPtr = TestFunction; //Diese Zeile geht NICHT!
  57. Ptr myPtr2(TestFunction); //Diese Zeile geht!
  58. myPtr.GetPtr()();
  59. }
  60.  
  61. void TestClass::TestFunction()
  62. {
  63. std::wcout << L"Geht doch!" << std::endl;
  64. }
  65.  
  66. int main()
  67. {
  68. TestClass myTestClass;
  69. std::wcout << L"Press any Key to exit!" << std::endl;
  70. std::cin.get();
  71. return 0;
  72. }
Success #stdin #stdout 0s 2848KB
stdin
Standard input is empty
stdout
Geht doch!
Press any Key to exit!