If the signal/slot is overloaded, disambiguate using static_cast<>

Fixes #1
Flush the output streams after every replacement
Add test case for #2