Since I have this warning my virtual functions do not work anymore.
It’s as if they don’t exist. The program simply ignores them… but it doesn’t crash.
Warning C4793: 'FProtocol::`vcall'{16}'': function compiled as native:
Non-clrcall vcall thunks must be compiled as native
It only happens with the CL compiler and in a Visual Studio (2022) project.
I made the following example and compiled it with CL in command line and there were no warnings and everything worked fine.(The code was deleted at the request of commentators).
I also tried with the GCC 14.2 compiler and it also ran without errors or warnings.
So I think it must be something related to the project settings in VisualStudio.
I tried this directive too but it didn’t fix the problem… it just hides the warnings.
#pragma unmanaged
Basically, the problem arises when I use pointers to virtual member functions (templates and non-templates).
Has anyone had this problem?
Have you been able to solve it in any way?
EDITED:
The problem is perfectly reproducible.
1-Create a C++ project in Visual Studio 2022
2-Configure it for managed code (Common Language Runtime)
3-Create a class, and a virtual member function
4-Create a pointer to that virtual function
5-DONE!! There you have the problem!!
Solution
Read the first comment provided by John