I have a template class ServoLink whose header file is in "/include" and whose source file is in "/src." The CMakeLists.txt file is in the project directory, in which the "include" and "src" folders reside. I started off declaring and defining all the functions in the header file, but I quickly realized my mistake, and I am trying to transfer the function definitions over to the source file. However, CLion tells me in the source file that none of the member variables of the class can be resolved.
The following is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(Two_Link_Leg)
set(CCMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -Wextra -pedantic -pedantic-errors")
include_directories("lib/Adafruit_PWMServoDriver")
include_directories(include)
set(SOURCE_FILES main.cpp src/ServoLink.cpp)
add_executable(Two_Link_Leg ${SOURCE_FILES})
ServoLink.h:
#ifndef TWO_LINK_LEG_SERVOLINK_H
#define TWO_LINK_LEG_SERVOLINK_H
#include <map>
#include "Adafruit_PWMServoDriver.h"
template <class size_t>
class ServoLink{
private:
//servo motor channel number on the PWM/Servo driver; [0, 15]
size_t mChannel;
//pointer to a map of the servo motor's angular position with its corresponding pulse width value
std::map<int, size_t>* mPWM;
//variable given by Adafruit
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
public:
ServoLink(size_t givenChannel, size_t givenPWM[]);
};
#include "../src/ServoLink.cpp"
#endif //TWO_LINK_LEG_SERVOLINK_H
ServoLink.cpp:
#include <stdexcept>
#include <map>
template<typename size_t size>
ServoLink<size_t>::ServoLink(size_t givenChannel, size_t givenPWM[]):mChannel(givenChannel){
mPWM= new std::map<int, size_t>;
for(size_t i= 0; i< size; i++){
mPWM->insert(std::make_pair(-90+((double)180*i/size), givenPWM[i]));
}
}
If there is any syntactical error in my template code or a mistake in the CMakeLists.txt, I would appreciate any help in identifying them. Thank you.