I have a comprehension problem with creating a static function. I declare in my header file a static function like below.
namespace detection {
class DetectionModel {
public:
// Functions
public:
DetectionModel();
~DetectionModel();
void calculate_bb_into_meter(std::vector<bb_in_pixel> &list_bb_in_pixel, pcl::PointCloud<pcl::PointXYZ> &point_cloud);
static bool is_valid_deviation(float value, float value_to_check, float deviation_in_percent);
};//end class
}// end namespace ObjectDetection
If I now want to define this function in my .cpp file as follows I get a compiler error.
'static' can only be specified inside the class definition
static bool DetectionModel::is_valid_deviation(float value, float value_to_check, float deviation_in_percent)
{
float deviation = value * deviation_in_percent/100;
return (value_to_check < (value + deviation)) && (value_to_check > (value - deviation));
}
If I leave out the word static in the declaration it works without problems and I can use the function as follows without creating an object in advance.
std::cout << " test: " << detection::DetectionModel::is_valid_deviation(5.0f,5.0f,5.0f) << "\n";
Can someone please explain to me why I get an error when I use the word static in the .cpp file? I think a detailed explanation of what the compiler does would be helpful.
Thanks for the help!