URL: https://www.overclockers.at/coding-stuff/c-no-matching-function-for-call-to-unresolved-overloaded-function-type_240204/page_1 - zur Vollversion wechseln!
ich programmiere gerade meinen arduino, und benutze dafür die accelstepper library. die hat einen konstruktor, der wie folgt ausschaut:
der wird so aufgerufen:Code: CPP/// Alternate Constructor which will call your own functions for forward and backward steps. /// You can have multiple simultaneous steppers, all moving /// at different speeds and accelerations, provided you call their run() /// functions at frequent enough intervals. Current Position is set to 0, target /// position is set to 0. MaxSpeed and Acceleration default to 1.0. /// Any motor initialization should happen before hand, no pins are used or initialized. /// \param[in] forward void-returning procedure that will make a forward step /// \param[in] backward void-returning procedure that will make a backward step AccelStepper(void (*forward)(), void (*backward)());
wobei die beiden parameter folgende funktionen sind:Code: CPPAccelStepper stepper1(forwardstep1, backwardstep1);
das funktioniert auch wunderbar, solange alles in dem main sketch liegt. jetzt habe ich mir eine klasse gebaut:Code: CPP// you can change these to SINGLE or DOUBLE or INTERLEAVE or MICROSTEP! // wrappers for the first motor! void forwardstep1() { AFstepper1->onestep(FORWARD, stepType1); } void backwardstep1() { AFstepper1->onestep(BACKWARD, stepType1); }
.cpp file:Code: CPP//Filter Wheel #ifndef FILTERWHEEL_H_INCLUDED #define FILTERWHEEL_H_INCLUDED #endif #include "Device.h" #include <Wire.h> #include <Adafruit_MotorShield.h> #include <AccelStepper.h> #define IICADDRESS 0x60 class FilterWheel : public Device { public: //blabla FilterWheel(); private: //Adafruit Motor Shield object Adafruit_MotorShield AFMS; //Adafruit Stepper Motor object Adafruit_StepperMotor *AFstepper; //AccelStepper wrapper AccelStepper stepper; void forwardstep(); void backwardstep(); float gearRatio; int numberOfFilters; uint8_t stepType; };
in der .cpp file, zeile 10 wirft mit der compiler folgende fehlermeldung (egal ob die beiden funktionen public oder private sind):Code: CPP//Filter Wheel #include "FilterWheel.h" //constructor FilterWheel::FilterWheel() { Adafruit_MotorShield AFMS (IICADDRESS); Adafruit_StepperMotor *AFstepper = AFMS.getStepper(200, 1); //M1 M2 AccelStepper stepper(forwardstep, backwardstep); } //make 1 step forward void FilterWheel::forwardstep() { AFstepper->onestep(FORWARD, stepType); } //make 1 step backward void FilterWheel::backwardstep() { AFstepper->onestep(BACKWARD, stepType); }
weis jemand wie ich das problem lösen kann? wenn ich die zeile auskommentiere kompiliert der code problemlos.Code:FilterWheel.cpp:In constructor 'FilterWheel::FilterWheel()' FilterWheel.cpp:10: error: no matching function for call to 'AccelStepper::AccelStepper(<unresolved overloaded function type>, <unresolved overloaded function type>)' AccelStepper.h:AccelStepper(void (*)(), void (*)()) AccelStepper.h:AccelStepper(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, bool) AccelStepper.h:AccelStepper(const AccelStepper&) Error compiling
gehts auch nicht:Code: CPPAccelStepper stepper(&forwardstep, &backwardstep);
die klasse Device ist eine leere klasse, hat (noch) keine funktionen oder variablen.Code:FilterWheel.cpp:In constructor 'FilterWheel::FilterWheel()' FilterWheel.cpp:10: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&FilterWheel::forwardstep' FilterWheel.cpp:10: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function. Say '&FilterWheel::backwardstep' FilterWheel.cpp:10: error: no matching function for call to 'AccelStepper::AccelStepper(void (FilterWheel::*)(), void (FilterWheel::*)())' AccelStepper.h:AccelStepper(void (*)(), void (*)()) AccelStepper.h:AccelStepper(uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, bool) AccelStepper.h:AccelStepper(const AccelStepper&) Error compiling
mit funktions-zeigern kennst du dich aus?
http://www.cprogramming.com/tutoria...n-pointers.html
nein. hab mich jetzt ein bisschen damit herumgespielt,aber weiter als bis zu
bin ich noch nicht gekommen.Code:FilterWheel.cpp:In constructor 'FilterWheel::FilterWheel()' FilterWheel.cpp:8: error: cannot convert 'void (FilterWheel::*)()' to 'void (*)()' in assignment FilterWheel.cpp:9: error: cannot convert 'void (FilterWheel::*)()' to 'void (*)()' in assignment Error compiling
.cpp file:Code: CPP//Filter Wheel #ifndef FILTERWHEEL_H_INCLUDED #define FILTERWHEEL_H_INCLUDED #endif #include "Device.h" #include <Wire.h> #include <Adafruit_MotorShield.h> #include <AccelStepper.h> #define IICADDRESS 0x60 class FilterWheel : public Device { public: //blabla FilterWheel(); void forwardstep(); void (*fwdstp)(); void backwardstep(); void(*bckwdstp)(); private: //Adafruit Motor Shield object Adafruit_MotorShield AFMS; //Adafruit Stepper Motor object Adafruit_StepperMotor *AFstepper; //AccelStepper wrapper AccelStepper stepper; float gearRatio; int numberOfFilters; uint8_t stepType; };
ergibtCode: CPP//Filter Wheel #include "FilterWheel.h" //constructor FilterWheel::FilterWheel() { fwdstp = &FilterWheel::forwardstep; bckwdstp = &FilterWheel::backwardstep; Adafruit_MotorShield AFMS (IICADDRESS); Adafruit_StepperMotor *AFstepper = AFMS.getStepper(200, 1); //M1 M2 AccelStepper stepper(fwdstp, bckwdstp); } //make 1 step forward void FilterWheel::forwardstep() { AFstepper->onestep(FORWARD, stepType); } //make 1 step backward void FilterWheel::backwardstep() { AFstepper->onestep(BACKWARD, stepType); }
Code:FilterWheel.cpp:In constructor 'FilterWheel::FilterWheel()' FilterWheel.cpp:8: error: cannot convert 'void (FilterWheel::*)()' to 'void (*)()' in assignment FilterWheel.cpp:9: error: cannot convert 'void (FilterWheel::*)()' to 'void (*)()' in assignment Error compiling
Z.B. http://stackoverflow.com/questions/...n-as-a-callback
danke für den link, leider hilft er mir überhaupt nichtZitat von RingdingZ.B. http://stackoverflow.com/questions/...n-as-a-callback
Code: CPPbind1st(&FilterWheel::forwardstep, this);
wobei ich aber gar nicht weis ob ich die funktion richtig aufrufe, oder ob die für meinen zweck geeignet ist. hier eine doku.Code:functional:In instantiation of 'std::binder1st<void (FilterWheel::*)()>' FilterWheel.cpp:instantiated from here functional:*)()' is not a class, struct, or union type functional:*)()' is not a class, struct, or union type functional:*)()' is not a class, struct, or union type functional:*)()' is not a class, struct, or union type functional:In function 'std::binder1st<Operation> std::bind1st(const Operation&, const T&) [with Operation = void (FilterWheel::*)(), T = FilterWheel*]' FilterWheel.cpp:instantiated from here functional:*)()' is not a class, struct, or union type Error compiling
Schau dir mal "mem_fun" an:
http://www.cplusplus.com/reference/functional/mem_fun/
Code: CPPAccelStepper stepper(mem_fun(&FilterWheel::forwardstep), mem_fun(&FilterWheel::backwardstep));
Ich war anscheinend ein bisschen voreilig, ich muss mir das nochmal anschauen.Zitat von wergordanke für den link, leider hilft er mir überhaupt nicht
Wie in dem letzten Stackoverflow-Link (EDIT: Den mit "demote boost::function" meine ich) beschrieben, kann es nicht wirklich gehen. Normalerweise bekommen solche Callbacks ein void * übergeben, das man durchreichen kann. In diesem Fall ist das nicht der Fall, daher bleibt nur die Möglichkeit, die Objektinstanz in einer globalen Variable abzulegen:
Code: CPP#include <iostream> using std::cout; using std::endl; struct AccelStepper { AccelStepper(void (*forward)(), void (*backward)()): forward(forward), backward(backward) { } enum Direction { FORWARD, BACKWARD }; void oneStep(Direction); private: void (*forward)(); void (*backward)(); }; void AccelStepper::oneStep(Direction dir) { switch (dir) { case FORWARD: forward(); break; case BACKWARD: backward(); break; } } struct FilterWheel { void forward() { cout << "forward" << endl; } void backward() { cout << "backward" << endl; } }; static FilterWheel *the_wheel; static void fwd_trampoline() { the_wheel->forward(); } static void bckwd_trampoline() { the_wheel->backward(); } int main() { FilterWheel wheel; the_wheel = &wheel; AccelStepper stepper(fwd_trampoline, bckwd_trampoline); stepper.oneStep(AccelStepper::FORWARD); stepper.oneStep(AccelStepper::BACKWARD); return 0; }
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025