文件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
为什么我可以从常规函数调用静态模板函数,而不是从静态模板函数内部调用?
答案 0 :(得分:0)
如果我在SecurityController中声明HallSensor类,我可以编译它。
e.g。
template <Axis axis> class HallSensor;
我不知道为什么这是必要的,因为我直接包括“hallSensor.h”..