why the 'try' don't catch the __attribute__((weak)) error?
i get a window: "the program stops responding" https://imgur.com/a/0e9f8ZX
what you can tell me?
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 not sure then, maybe mbozzi knows. Would you mind posting your full source code file that gives you that particular output? Your above post isn't actually your full code.
Also, if you're working in an IDE or something, try cleaning your project (maybe something leftover from a previous build).
If you are indeed using GCC or Clang, please post the output of the command g++ --version -v
or clang++ --version -v
And whatever command(s) you're using to compile and link the above.
- 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)