Replies: 1 comment 1 reply
-
@LJ2911 I think the solution with The class used in sdbus-c++ API must either be default-constructible, or you cannot use it with sdbus-c++. Your class cannot be even used in Alternative solutions that quickly come to my mind:
|
Beta Was this translation helpful? Give feedback.
-
Hi!
I'm looking for some help with a slightly obscure use-case I currently have. In my application I have a class definition that has no default constructor and wish to keep it this way as the default constructed object would be invalid and I don't want users to be able to interact with it (and don't want to add validity checks to all methods in the class), however, I also wish to be able to use this class as an sdbus::Signal argument.
There are one or two other libraries that my application interacts with using this type and I have successfully been able to add a friend declaration to the class in order for those libraries to be able to default construct an object (using a private default constructor) as I know the data will then get correctly populated shortly after using the assignment operator. However, I am having no luck doing the same here.
My class at it's core is a wrapper for a string_view that constricts to pointing at certain static strings (that have a guaranteed lifetime) and has custom methods for interacting with it, so I implemented the following (de)serialisation methods in the sdbus namespace first:
I have then tried adding these friend declarations to my class and have had no joy with any of them:
For reference, the signal I am trying to implement has a signature
void(my::CustomClass, int64_t)
in case you were wondering what thestd::function
template args are about and I implement a wrapper for sdbus-cpp that requires astd::function
to be provided as the callback which I use tostd::bind
member functions to in consumers. The compilation error I am getting is:Also, for reference, I am using version 0.8.3-4 of this library and unfortunately don't have scope to move to a newer version at present.
Beta Was this translation helpful? Give feedback.
All reactions