I have come across an example in ros2 using : for a class constructor:
class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher()
: Node("minimal_publisher"), count_(0)
{
publisher_ = this->create_publisher<std_msgs::msg::String>("topic", 10);
timer_ = this->create_wall_timer(
500ms, std::bind(&MinimalPublisher::timer_callback, this));
}
here in the above lines -- why is MinimalPublisher() : Node("minimal_publisher"), count_(0) declared like this and not inside the constructor? i can refer from this question What is this weird colon-member (" : ") syntax in the constructor? that it is called member Initializer list. but my question is here, there are some values written directly has member Initializer list and some as individual lines. what calls for this difference as the function needs to be called anyway as there are other instructions in the function?
i tried to search the significance of :and i found this member Initializer list What is this weird colon-member (" : ") syntax in the constructor? but i didnt get y its used here in this senario.
Aucun commentaire:
Enregistrer un commentaire