# Unsubscribe messages in lib

**URL:** <https://forum.opencyphal.org/t/unsubscribe-messages-in-lib/295>\
**Category:** LibCyphal\
**Created:** [December 16, 2018, 10:20am UTC](https://forum.opencyphal.org/t/unsubscribe-messages-in-lib/295 "2018-12-16T10:20:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![deekay](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@deekay](https://forum.opencyphal.org/u/deekay)\
**Post date:** [December 16, 2018, 10:20am UTC](https://forum.opencyphal.org/t/unsubscribe-messages-in-lib/295/1 "2018-12-16T10:20:24Z")

</div>

It is clear how to subscribe to multicast messages. But is it possible to unsubscribe ? I have a scenario when nodes are coming and going to/from the bus and subscriptions are done during runtime. Of course I can reuse the subscriptions if the same node comes back, but it is not as cool 😉.

Is it somehow possible with the generalsubscriber class?

I think the same question relates to registered services as well…

Kind regards

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [December 17, 2018, 9:05am UTC](https://forum.opencyphal.org/t/unsubscribe-messages-in-lib/295/2 "2018-12-17T09:05:54Z")

</div>

Just destroy the subscriber object. Same applies to services.

---

<div class="post-metadata">

**Author:** ![deekay](https://forum.opencyphal.org/letter_avatar_proxy/v4/letter/d/8491ac/32.png) [@deekay](https://forum.opencyphal.org/u/deekay)\
**Post date:** [December 17, 2018, 3:49pm UTC](https://forum.opencyphal.org/t/unsubscribe-messages-in-lib/295/3 "2018-12-17T15:49:14Z")

</div>

Ok! Thanks.

Follow up question:  
I am now deriving uavcan::Subscriber i my own class (MyClass). I.e.

```auto
class MyClass: public uavcan::Subscriber<MyDataType>
{
  public: 
  MyClass(NodePtr& node) : uavcan::Subscriber<MyDataType>(*node)
  {
    ...
    ...
  }
}

```

So far no problems. But since my system dynamically detects nodes, I have a

`std::vector<MyClass>`

that is collects all detected nodes. But this creates problems on the subscribers. I get Noncopyable errors etc…  
I am probably doing this the wrong way…

Do you have a suggestion on how to store the classes in a proper way without using pointers?

---

<div class="post-metadata">

**Author:** ![pavel.kirienko](https://forum.opencyphal.org/user_avatar/forum.opencyphal.org/pavel.kirienko/32/9_2.png) [@pavel.kirienko](https://forum.opencyphal.org/u/pavel.kirienko)\
**Post date:** [December 17, 2018, 5:09pm UTC](https://forum.opencyphal.org/t/unsubscribe-messages-in-lib/295/4 "2018-12-17T17:09:47Z")

</div>

> Do you have a suggestion on how to store the classes in a proper way without using pointers?

As the name suggests, noncopyable objects can’t be copied. The implication is that you can’t use them with containers that implicitly relocate their storage, such as `std::vector<>`.

You can either find some container that does not move its items around (some form of non-contiguous containers such as linked lists or queues should work; however, I don’t think such containers exist in the STL), or you can add an extra level of indirection to create movable references to immovable (noncopyable) objects, such as `std::shared_ptr<>` (or some other kind of pointers).

If you’re keen to stick with vectors, use `std::vector<std::shared_ptr<MyClass>>`.
