0

Say I want to implement a signal system based on ordered slots and I would also be able to block the connection toward a function. To be more clear:

Case Full Connection: mysignal("string","string") this connects to both functions.

Case Selected: mysignal("string","string") sends only to func1_receiver

Case None: mysignal("string","string") blocked

So my code is something like this:

/*declaring mysignal with two string arguments*/
boost::signals2::signal<void (string,string)> mysignal;

/*declaring connections*/
boost::signals2::connection to_func_1 = mysignal.connect (0,&func1_receiver); 
boost::signals2::connection to_func_2 = mysignal.connect (1,&func2_receiver);

Now if I would like to block a slot I should write:

boost::signals2::shared_connection_block block(to_func_2);

All this works fine.

If I want to block also the second slot I should cast a:

boost::signals2::shared_connection_block block(to_func_1);

Here I get an error: "redeclaration of 'boost::signals2::shared_connection_block block'"

I supposed I could block/unblock connections at will, but I'm misunderstood something.

Could someone help me ?

Podarce
  • 473
  • 1
  • 6
  • 22
  • 1
    Not sure I completely understand the problem but... just give the two variables different names -- `block_1` and `block_2` for example. – G.M. Jul 21 '17 at 10:39
  • 1
    Indeed, with your current description it looks unrelated to `boost::signals2`, it just seems as if you're trying to declare a new variable with a same name as an already existing one. The same error would occur if you wrote something like `int x = 24; int x = 42;` – Vasiliy Galkin Jul 21 '17 at 10:44
  • Indeed you both are right, "block" is an object so I should give different names. If I need to unblock it i just need to cast: block.unblock(); and looks like this destroys the block object, infact if I want to block again I should recast the boost::signals2::shared_connection_block block(to_func_2) again. Am I right on this ? – Podarce Jul 21 '17 at 10:46
  • My misunderstanding was about thinking that shared_connection_block was a kind of a method for the signal class. But indeed it's another class where the constructor gets a connection as parameter. Now it's all clear. Thanks a lot for your help. – Podarce Jul 21 '17 at 11:02

0 Answers0