Query related to exercise 6.1 solution

In the execercise 6.1 solution. you have created a new template variable ( CallBackROSMessageType) for CallbackToTopic function. But, you never used it inside the function. I am wondering is it a type or is there any explanation for that. I have pasted the related lines of code below

template <typename CallBackROSMessageType>
  void CallbackToTopic(const typename ROSMessageType::ConstPtr &msg) {
    // the uint8 is an alias of unsigned char, therefore needs casting to int
        "Call Back Topic Image Data[0]=" << static_cast<int>(msg->data[0]));


Its explained in this section

  • In the CallbackToTopic, we NEED to declare a NEW template header. And it has a different name because otherwise it would shadow the one declared at the top of the class. Also because the CallbackToTopic doesn’t necessarily need the same number of template type variables. It mght need more!

  • Thats why we use this structure:

template <typename CallBackROSMessageType>

void functionName(typename CallBackROSMessageType){...};

We use another name so it doesn’t shadow the ROSMessageType. Its that the only reason why we put it like this. But its true that inside ewe are still using the ROSMessageType. If you place the same one, it will give issues.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.