0

I have a class like this:

class MyClass
{
    public:
    void GetForm() {}
};

Now I want to call GetForm:

MyClass myobj;
myobj.GetForm();

And at compilation I get this error:

error: 'class MyClass' has no member named 'GetFormA'; did you mean 'GetForm'?

What I have found is that in a file (winspool.h), there is a definition:

#define GetForm __MINGW_NAME_AW(GetForm)

And this results in GetFormA I guess for encoding thing.

But, how can it be possible that a #define replace in a name of a function of an object?

How can resolve this?

Mert Mertce
  • 1,049
  • 7
  • 34
  • 2
    _"But, how can it be possible that a `#define` replace in a name of a function of an object?"_ Because the preprocessor is just a dumb text replacing tool more or less. – πάντα ῥεῖ Jan 20 '21 at 18:21
  • 2
    Oh, if you think this is wild, for a `#define`, then try this: `#define if while`. – Sam Varshavchik Jan 20 '21 at 18:23
  • Wow, I knew Winapi is weird, but this is a whole next level. You can try `#undef GetForm`, but I can't guarantee that it will not break some other things. – Yksisarvinen Jan 20 '21 at 18:28
  • 1
    @Yksisarvinen In c++ the best option probably is to wrap the whole access to that module in proper template class interfaces. This would separate the plain WinAPI stuff from other (e.g. GUI) frameworks and classes. – πάντα ῥεῖ Jan 20 '21 at 18:34
  • Thank you @Yksisarvinen for suggesting a solution before attacking as if I was the one who put this macro. – Mert Mertce Jan 20 '21 at 18:34
  • @MertMertce Who attacked you because of that? – πάντα ῥεῖ Jan 20 '21 at 18:35
  • It is closed in seconds with a link that tells "Why are preprocessor macros evil?". Good, macros are evil, and how does this answer the question? I have not created the macro. Should I modify winapi?? – Mert Mertce Jan 20 '21 at 18:39
  • @MertMertce It's mentioned in the answers there, that you can `#undef` that macro, to not be applied to your code. Anoother alternative is to decouple that stuff completely using your own interface definitons. – πάντα ῥεῖ Jan 20 '21 at 18:47
  • Welcome to Windows. One possible solution is to put `#include ` in the header file as well as the source file. That way you get the same source-code stomping in both files. – Pete Becker Jan 20 '21 at 19:04

0 Answers0