файл securityController.h (сокращенный)
#ifndef SECURITYCONTROLLER_H_
#define SECURITYCONTROLLER_H_
#include "hallSensor.h"
#include "project.h"
template<Axis axis>
class SecurityController{
public:
static void saturate(double& value){
HallSensor<X>::isAtEnd(); // DOES NOT WORK, nor do the other calls
}
};
#endif /* SECURITYCONTROLLER_H_ */
файл hallSensor.h (сокращенный)
#ifndef HALLSENSOR_H_
#define HALLSENSOR_H_
#include "project.h"
#include "control.h"
template<Axis axis>
class HallSensor{
private:
static volatile bool triggered[2];
static volatile bool state[2]; //the real current state
static volatile int triggeredPosition[2];
public:
static bool isAtEnd(){
return triggered[1];
}
};
template<Axis axis> volatile bool HallSensor<axis>::triggered[2];
template<Axis axis> volatile bool HallSensor<axis>::state[2];
template<Axis axis> volatile int HallSensor<axis>::triggeredPosition[2];
template<> bool HallSensor<ALL>::init();
#endif /* HALLSENSOR_H_ */
Это работает: (main.cpp)
#include "hallSensor.h"
int main(){
HallSensor<X>::isAtEnd(); } //WORKS
Вызовы внутри securityController.h не работают. Gcc/c++ выводит следующее:
securityController.h: In static member function 'static void SecurityController<axis>::saturate(double&)':
securityController.h:19:3: error: 'HallSensor' was not declared in this scope
HallSensor<X>::isAtEnd();
^
securityController.h:19:16: error: '::isAtEnd' has not been declared
HallSensor<X>::isAtEnd(); //and so on
Axis - это простое перечисление со значениями для X, Y, Z, All
Почему я могу вызвать статическую функцию шаблона из обычной функции, но не изнутри статической функции шаблона?
Я могу его скомпилировать, если я переадресую класс HallSensor в SecurityController.
например
template <Axis axis> class HallSensor;
У меня нет идеи, почему это необходимо, так как я включаю "hallSensor.h" напрямую..