Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Grayhill61C.h:
- --------------------------------------
- #ifndef GRAYHILL61C_H
- #define GRAYHILL61C_H
- #include "Arduino.h"
- // Generic definition of the function type
- template <typename F>
- class function;
- // R: return type
- // Args: Any arguments a function can take
- template <typename R, typename... Args>
- class function<R(Args...)> {
- public:
- // Type definition of the equivalent C function pointer
- using function_type = R (*)(Args...);
- // Constructor: store the function pointer
- function(function_type f) : function_ptr(f){};
- // Call operator: calls the function object like a normal function
- // PS: This version does not do perfect forwarding.
- R operator()(Args... args) { return function_ptr(args...); }
- private:
- function_type function_ptr;
- };
- // A helper function can be used to infer types!
- template <typename R, typename... Args>
- function<R(Args...)> make_function(R (*f)(Args...)) {
- return {f};
- }
- class Grayhill61C {
- int OutputA, OutputB, rotationCount, rotationDir, oldA, oldB, previousPinChange;
- function<void()> increment;
- function<void()> changeDirection;
- public:
- Grayhill61C(int, int, function<void()>, function<void()>);
- ~Grayhill61C();
- void tick();
- };
- #endif
- --------------------------------------
- Beginning of Grayhill61C.cpp:
- --------------------------------------
- #include "Grayhill61C.h"
- Grayhill61C::Grayhill61C(
- int oa,
- int ob,
- function<void()> iIncrement,
- function<void()> iChangeDirection
- ) {
- OutputA = oa;
- OutputB = ob;
- increment = iIncrement;
- changeDirection = iChangeDirection;
- pinMode(OutputA, INPUT);
- pinMode(OutputB, INPUT);
- rotationCount = 0;
- rotationDir = 1;
- oldA = -1;
- oldB = -1;
- previousPinChange = 9;
- //void* changeDirection = (*iChangeDirection);
- }
- --------------------------------------
- Part of my main ino file that uses my class:
- --------------------------------------
- #include "Grayhill61C.h"
- void encStep() {
- }
- void encDir() {
- }
- Grayhill61C enc = Grayhill61C(9, 10, make_function(encStep), make_function(encDir));
- --------------------------------------
- Full error message from IDE:
- --------------------------------------
- sketch/Grayhill61C.cpp: In constructor 'Grayhill61C::Grayhill61C(int, int, function<void()>, function<void()>)':
- Grayhill61C.cpp:8:3: error: no matching function for call to 'function<void()>::function()'
- ) {
- ^
- In file included from sketch/Grayhill61C.cpp:1:0:
- 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 (*)()]
- function(function_type f) : function_ptr(f){};
- ^
- sketch/Grayhill61C.h:19:3: note: candidate expects 1 argument, 0 provided
- sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(const function<void()>&)
- class function<R(Args...)> {
- ^
- sketch/Grayhill61C.h:13:7: note: candidate expects 1 argument, 0 provided
- sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(function<void()>&&)
- sketch/Grayhill61C.h:13:7: note: candidate expects 1 argument, 0 provided
- Grayhill61C.cpp:8:3: error: no matching function for call to 'function<void()>::function()'
- ) {
- ^
- In file included from sketch/Grayhill61C.cpp:1:0:
- 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 (*)()]
- function(function_type f) : function_ptr(f){};
- ^
- sketch/Grayhill61C.h:19:3: note: candidate expects 1 argument, 0 provided
- sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(const function<void()>&)
- class function<R(Args...)> {
- ^
- sketch/Grayhill61C.h:13:7: note: candidate expects 1 argument, 0 provided
- sketch/Grayhill61C.h:13:7: note: candidate: constexpr function<void()>::function(function<void()>&&)
- sketch/Grayhill61C.h:13:7: note: candidate expects 1 argument, 0 provided
- exit status 1
- no matching function for call to 'function<void()>::function()'
- --------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement