- I am creating a ros-node talker to read the CAN bus data and decode.
- To do that, I have to call a function from another
cpp
file (decoder).
How can I do that?
cpp
file (decoder).How can I do that?
In order to use a function from some cpp file (say a.cpp
) a matching header file (a.h
here) should contain the signature of that function.
That is, its name, return type and list of input parameters, without the actual body. Then, if another cpp file b.cpp
states #include a.h
it ca freely use every function listed in that header file.
$ cat a.cpp
int add(unsigned int x,unsigned int y){return x+y;}
$ cat a.h
int add(unsigned int x,unsigned int y);
$ cat b.cpp
#include "a.h"
int mul(unsigned int p,unsigned int q)
{
if (p=0) return 0;
else return add(mul(p-1,q),q);
}