How to use custom c++ class/oject
I am trying to use a custom object in my ROS program but having issues linking everything.
I have seen older answers from ~6 years ago and have not seen any answers on how to do this in ROS indigo/kinetic. I have tried those answers and it did not work so my guess is something has changed in the catkin build requirements.
So my question is:
1) How to use custom objects in my ROS packages? and what is the best way if I want to use this object in multiple ROS packages.
// my_class.h
class MyClass {
public:
int a;
int b;
int addNumbers() const;
}
// my_class.cpp
#include "my_class.h"
void MyClass::addNumbers() const {
return a + b;
}
This is standard CMake stuff. You need to create a new ROS package that builds a library and use it from your other nodes. Either look at a CMake tutorial to learn how to add additional libraries, or post the errors you are getting.
There is a quite complete catkin documentation that should answer all your questions.
Other than that, I'm seconding @Geoff.
+1000; I cannot emphasise this enough.
@AC3021: how do you expect us to help you if you don't show/tell us what sort of "issues linking" you have?
Not a lot changed in the past 6 years that influences this. As @Geoff writes: this is CMake, not Catkin.