# Cant pass laserscan massage betwene functions iside a class?(read last replay)

**URL:** <https://get-help.theconstruct.ai/t/cant-pass-laserscan-massage-betwene-functions-iside-a-class-read-last-replay/7810>\
**Category:** ROS Basics In 5 Days (C++)\
**Created:** [January 23, 2021, 10:34am UTC](https://get-help.theconstruct.ai/t/cant-pass-laserscan-massage-betwene-functions-iside-a-class-read-last-replay/7810 "2021-01-23T10:34:31Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![bayodesegun](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/bayodesegun/32/10684_2.png) [@bayodesegun](https://get-help.theconstruct.ai/u/bayodesegun)\
**Post date:** [January 25, 2021, 9:49am UTC](https://get-help.theconstruct.ai/t/cant-pass-laserscan-massage-betwene-functions-iside-a-class-read-last-replay/7810/10 "2021-01-25T09:49:56Z")

</div>

Hi Ziga,

Quite an interesting monologue!

I can’t help much with the C++ part, but there’s something missing in your code, which seems to be causing your head to `spin()` 😃:

> You need to include `ros::spin()` in your class `init` method, where your subscriber and publisher are initialized.

`ros::spin()` ensures that your subscriber messages arrive. It seems your messages were not arriving; with `spin()` included, you shouldn’t need to publish to the laser\_scan message manually, neither do you need `spinOnce()`.

`ros::spin()` and `rospy.spin()` are different, and here lies the difference. See this post for details:

> **[What is rospy.spin(), ros::spin(), ros::spinOnce(), and what are they for?](https://get-help.theconstruct.ai/t/what-is-rospy-spin-ros-spin-ros-spinonce-and-what-are-they-for/58)**
>
> First, let make a distinction based on the ROS API: rospy.spin() - used by ROS Python API. ros::spin() and ros::spinOnce() - used by ROS C++ API. That said, what are they for? They are all used in connection with subscribers. rospy.spin()...

---

_[View the full topic](https://get-help.theconstruct.ai/t/cant-pass-laserscan-massage-betwene-functions-iside-a-class-read-last-replay/7810)._
