I'm not an expert in this, but are you trying to implement the Curiously Recurring Template Pattern (CRTP)?
I believe you are erroneously trying to use weak symbols in an attempt to cover up the actual problem: you never define an implementation for InstanceName::MouseClick(), but then try to call it within your test constructor. I don't quite understand what you're doing here.
A function that isn't implemented doesn't throw an exception, as far as I know, you simply are dereferencing a function that doesn't exist -- this is undefined behavior.
Also, in general avoid global objects, like your InstanceName object. Define it in main or another function instead.
If you don't comment out line 38 in mbozzi's code, the output will be "button clicked"
If you do comment out line 38, Derived::mouse_click will be a null function pointer, and the output should be "no definition", with no runtime errors happening. Are you experiencing different behavior?
mbozzi's code works on MinGW (Windows) for me, as well.
Edit: I realize you posted at almost the same time as mbozzi, so you might not have seen his post.
- i'm using Code blocks 17.12(from 25 December 2017.. maybe it's updated, but i must see) with Mingw 5.1.0 (came with code blocks installer.. maybe it's a big problem... the Mingw can't be updated(i accept more info about the Code Blocks came with Mingw);
- but i have installed the Mingw 7.2.0;
- yes i know change the Compiler folder and files.
- and yes.. thank you.. i have the 'Clean' command on Build menu.
and now works just fine...
(i did with new names, on macros)