jeudi 18 juillet 2019

Pass parameter on constructor or pass them on each method

I'm learning C++ and I have this header file:

#ifndef _ROBOT_MOVE_H__
#define _ROBOT_MOVE_H__ 1

#include "ros/ros.h"

class RobotMove
{
private:
    double current_linear;
    double current_angular;
public:
    void TurnLeft(const ros::Publisher& publisher, ros::Rate& loop_rate);
    void TurnRight(const ros::Publisher& publisher, ros::Rate& loop_rate);
    void TurnAround(const ros::Publisher& publisher, ros::Rate& loop_rate);
    void Forward(const ros::Publisher& publisher, ros::Rate& loop_rate);
    void Backward(const ros::Publisher& publisher, ros::Rate& loop_rate);
    void Stop();

    RobotMove();
    ~RobotMove();
}


#endif

I don't know if it is better to pass const ros::Publisher& publisher, ros::Rate& loop_rate once, on the constructor, or pass them every time I call the other methods.

Is it better to pass these two parameters in constructor and store a pointer in the class or pass them on each method?

By the way, the two parameter will be always the same objects.

Aucun commentaire:

Enregistrer un commentaire