CsSignal can only connect to references?!
Posted: Tue Dec 06 2022 10:51 pm
I am converting some code to CsSignal,which seems rather straightforward: derive classes from CsSignal::SignalBase and CsSignal::SignalSlot, replace existing connections (which already use &Class::member pointers) with connect(). Of course we use pointers, but CsSignal does not support them, only references??
This is the old code:
I expect that code to convert to:
But this fails with the following compiler message (Visual Studio 2022):
The only way to get it compiled is by dereferencing the pointers:
I looked at the code in cs_signal.h and there does not seem to be any code that connects pointers of objects, only references. Why? 99.99% of our code deals with pointers. Sure I can add the '*' but that just looks, for lack of a better word, ugly. For the sender object I might concur, but '*this'? [1]
Before I continue with the conversion I would like know a bit more about the reasoning behind this design.
[1] I know *this will work,I just have never been forced to use it this way.
This is the old code:
Code: Select all
channel->LogEvent.connect (this, &Export::channelEvent);
Code: Select all
connect (channel, &Channel::LogEvent, this, &Export::channelEvent);
Code: Select all
C2338: static_assert failed: 'connect(): Signal was not a child class of Sender'
C2338: static_assert failed: 'connect(): Slot was not a child class of Receiver'
C2530: 'item': references must be initialized
C3531: 'item': a symbol whose type contains 'auto' must have an initializer
C2143: syntax error: missing ';' before ':'
C3536: 'senderListHandle': cannot be used before it is initialized
C2100: illegal indirection
C2143: syntax error: missing ';' before ')'
Code: Select all
connect (*channel, &Channel::LogEvent, *this, &Export::channelEvent);
Before I continue with the conversion I would like know a bit more about the reasoning behind this design.
[1] I know *this will work,I just have never been forced to use it this way.