fyi I have looked at the other posts on this topic but I either didn't understand or didn't find my problem in them.
pretty much I am trying to put a class into a cpp and .h file, when I compile the code I get a warning saying "warning: inline function 'float map::get_mapped_value()' used but never defined.
And when I build the code I get an error saying undefined reference to 'map::get_mapped_value'
below are the code in each file
I thought I had all my includes correct, but maybe I am missing something, I am new to separating classes into seperate file, so any help would be greatly appreciated.
Thanks in advance, Dean.
map.cpp
#include "map.hpp"
#include <stdio.h>
#include <iostream>
using namespace std;
//------------------------Constructor definitions--------------------------
map::map(float Val_to_map_, float in_min_, float in_max_, float out_min_, float out_max_)
: Val_to_map(Val_to_map_)
, in_min(in_min_)
, in_max(in_max_)
, out_min(out_min_)
, out_max(out_max_)
{
}
//-------------------------------------------------------------------------
//------------------------Copy Constructor definitions---------------------
map::map(const map& mp)
: Val_to_map(mp.Val_to_map)
, in_min(mp.in_min)
, in_max(mp.in_max)
, out_min(mp.out_min)
, out_max(mp.out_max)
{
}
//-------------------------------------------------------------------------
//-----------------------equals function-------------------------------------
map& map::operator=(const map& mp)
{
if(this == &mp)
return (*this);
Val_to_map = mp.Val_to_map;
in_min = mp.in_min;
in_max = mp.in_max;
out_min = mp.out_min;
out_max = mp.out_max;
return (*this);
}
//---------------------------------------------------------------------------
//-------------------get function definitions--------------
inline float map::get_mapped_value()
{
return (float((Val_to_map - in_min) * (out_max - out_min) / (in_max - in_min) + out_min));
}
//-----------------------------------------------------------
//-------------------set function definitions----------------
inline void map::set_Val_to_map(float _Val_to_map)
{
Val_to_map = _Val_to_map;
}
inline void map::set_in_min(float _in_min)
{
in_min = _in_min;
}
inline void map::set_in_max(float _in_max)
{
in_max = _in_max;
}
inline void map::set_out_min(float _out_min)
{
out_min = _out_min;
}
inline void map::set_out_max(float _out_max)
{
out_max = _out_max;
}
//-----------------------------------------------------------
map.h
#ifndef MAP_HPP
#define MAP_HPP
using namespace std;
class map
{
public:
//----------------Special Member functions-----------------
map(float Val_to_map_, float in_min_, float in_max_, float out_min_, float out_max_); // accepted arguments
map(const map& m); // copy constructor
map& operator=(const map& m); // Equals function
~map()
{
} // destructor
//---------------------------------------------------------
//-----------------get functions-----------------
inline float get_mapped_value();
//------------------------------------------------
//-----------------set functions-----------------
inline void set_Val_to_map(float Val_to_map);
inline void set_in_min(float in_min);
inline void set_in_max(float in_max);
inline void set_out_min(float out_min);
inline void set_out_max(float out_max);
//------------------------------------------------
private:
float Val_to_map;
float in_min; // min Vref
float in_max; // max Vref
float out_min; // min output voltage from psu
float out_max; // max output voltage from psu
};
#endif // MAP_HPP
main.cpp
main(){
map voltage(1, map_in_min, map_in_max, map_out_min, map_out_max);
cout << "Mapped val: " << voltage.get_mapped_value() << endl;
}