我有一個模板類,在fsm.h文件 和derivata.h文件中的派生類; 編譯器會引發錯誤:從模板類繼承
derivata.h: In constructor ‘deri::deri()’:
derivata.h:46: error: no matching function for call to ‘fsm<pin_steps>::fsm()’
fsm.h:30: note: candidates are: fsm<step_type>::fsm(step_type) [with step_type = pin_steps]
fsm.h:12: note: fsm<pin_steps>::fsm(const fsm<pin_steps>&)
fsm.h:
#ifndef FSM_H_
#define FSM_H_
template<class step_type> class fsm {
protected:
step_type step;
step_type step_old;
step_type step_tmp;
bool step_pulse;
char name[256];
public:
fsm(step_type);
void set_name(char *parent, char *myname);
void test();
virtual void update(){cout << "base\n";};
void show(){cout << step << ' ' << step_tmp << '\n'; };
void init(step_type st_current) {step = st_current;};
//virtual ~fsm();
};
//constructor
template <class step_type> fsm<step_type>::fsm(step_type) {
step = step_old = step_tmp = (step_type)0 ;
step_pulse = false;
}
template <class step_type> void fsm<step_type>::set_name(char *parent, char *myname) {
sprintf(name, "%s.%s", parent, myname);
}
template <class step_type> void fsm<step_type>::test() {
if (step != step_old) {
step_pulse = true;
step_tmp = step_old;
} else step_pulse = false;
step_old = step;
}
#endif /* FSM_H_ */
,並從模板類派生類:
#include "fsm.h"
#ifndef DERIVATA_H_
#define DERIVATA_H_
enum taglio_steps {
ST_TAGLIO_CHECK_MOTORE,
ST_TAGLIO_ZERO_MOTORE,
ST_TAGLIO_WAIT_ZERO_MOTORE
};
enum pin_steps {
ST_PIN_BOOT,
ST_PIN_RETURN
};
class deri : public fsm<pin_steps>{
private:
bool cmd_prelevamento_done;
bool cmd_scorrimento_done;
float posizione_pinza_i;
float posizione_pinza_f;
public:
deri(){
cmd_prelevamento_done = false;
cmd_scorrimento_done = false;
posizione_pinza_i = 0;
posizione_pinza_f = 0;
};
void update(){cout << "deri\n";};
// virtual ~deri();
};
#endif /* DERIVATA_H_ */
歡迎!你可以把它減少到[testcase](http://sscce.org)嗎? –