Advertisement
merlin04

Code and errors

Aug 19th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.16 KB | None | 0 0
  1. Grayhill61C.h:
  2. --------------------------------------
  3. #ifndef GRAYHILL61C_H
  4. #define GRAYHILL61C_H
  5.  
  6. #include "Arduino.h"
  7.  
  8. // Generic definition of the function type
  9. template <typename F>
  10. class function;
  11.  
  12. // R: return type
  13. // Args: Any arguments a function can take
  14. template <typename R, typename... Args>
  15. class function<R(Args...)> {
  16.  public:
  17.   // Type definition of the equivalent C function pointer
  18.   using function_type = R (*)(Args...);
  19.  
  20.   // Constructor: store the function pointer
  21.   function(function_type f) : function_ptr(f){};
  22.  
  23.   // Call operator: calls the function object like a normal function
  24.   // PS: This version does not do perfect forwarding.
  25.   R operator()(Args... args) { return function_ptr(args...); }
  26.  
  27.  private:
  28.   function_type function_ptr;
  29. };
  30.  
  31. // A helper function can be used to infer types!
  32. template <typename R, typename... Args>
  33. function<R(Args...)> make_function(R (*f)(Args...)) {
  34.   return {f};
  35. }
  36.  
  37. class Grayhill61C {
  38.     int OutputA, OutputB, rotationCount, rotationDir, oldA, oldB, previousPinChange;
  39.     function<void()> increment;
  40.     function<void()> changeDirection;
  41.   public:
  42.     Grayhill61C(int, int, function<void()>, function<void()>);
  43.     ~Grayhill61C();
  44.     void tick();
  45. };
  46.  
  47. #endif
  48. --------------------------------------
  49. Beginning of Grayhill61C.cpp:
  50. --------------------------------------
  51. #include "Grayhill61C.h"
  52.  
  53. Grayhill61C::Grayhill61C(
  54.     int oa,
  55.     int ob,
  56.     function<void()> iIncrement,
  57.     function<void()> iChangeDirection
  58.   ) {
  59.   OutputA = oa;
  60.   OutputB = ob;
  61.   increment = iIncrement;
  62.   changeDirection = iChangeDirection;
  63.   pinMode(OutputA, INPUT);
  64.   pinMode(OutputB, INPUT);
  65.   rotationCount = 0;
  66.   rotationDir = 1;
  67.   oldA = -1;
  68.   oldB = -1;
  69.   previousPinChange = 9;
  70.   //void* changeDirection = (*iChangeDirection);
  71. }
  72. --------------------------------------
  73. Part of my main ino file that uses my class:
  74. --------------------------------------
  75. #include "Grayhill61C.h"
  76.  
  77. void encStep() {
  78.  
  79. }
  80.  
  81. void encDir() {
  82.  
  83. }
  84.  
  85. Grayhill61C enc = Grayhill61C(9, 10, make_function(encStep), make_function(encDir));
  86. --------------------------------------
  87. Full error message from IDE:
  88. --------------------------------------
  89. sketch/Grayhill61C.cpp: In constructor 'Grayhill61C::Grayhill61C(int, int, function<void()>, function<void()>)':
  90. Grayhill61C.cpp:8:3: error: no matching function for call to 'function<void()>::function()'
  91.    ) {
  92.    ^
  93. In file included from sketch/Grayhill61C.cpp:1:0:
  94. sketch/Grayhill61C.h:19:3: note: candidate: function<R(Args ...)>::function(function<R(Args ...)>::function_type) [with R = void; Args = {}; function<R(Args ...)>::function_type = void (*)()]
  95.    function(function_type f) : function_ptr(f){};
  96.    ^
  97. sketch/Grayhill61C.h:19:3: note:   candidate expects 1 argument, 0 provided
  98. sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(const function<void()>&)
  99.  class function<R(Args...)> {
  100.        ^
  101. sketch/Grayhill61C.h:13:7: note:   candidate expects 1 argument, 0 provided
  102. sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(function<void()>&&)
  103. sketch/Grayhill61C.h:13:7: note:   candidate expects 1 argument, 0 provided
  104. Grayhill61C.cpp:8:3: error: no matching function for call to 'function<void()>::function()'
  105.    ) {
  106.    ^
  107. In file included from sketch/Grayhill61C.cpp:1:0:
  108. sketch/Grayhill61C.h:19:3: note: candidate: function<R(Args ...)>::function(function<R(Args ...)>::function_type) [with R = void; Args = {}; function<R(Args ...)>::function_type = void (*)()]
  109.    function(function_type f) : function_ptr(f){};
  110.    ^
  111. sketch/Grayhill61C.h:19:3: note:   candidate expects 1 argument, 0 provided
  112. sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(const function<void()>&)
  113.  class function<R(Args...)> {
  114.        ^
  115. sketch/Grayhill61C.h:13:7: note:   candidate expects 1 argument, 0 provided
  116. sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(function<void()>&&)
  117. sketch/Grayhill61C.h:13:7: note:   candidate expects 1 argument, 0 provided
  118. exit status 1
  119. no matching function for call to 'function<void()>::function()'
  120. --------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement