Avega
Avega

Reputation: 186

Which compiler supported with function pointer with default arguments?

Which c++ compiler can compile next code?

void (*G2API_CopyGhoul2Instance)(CGhoul2Info_v &ghoul2From, 
                                 CGhoul2Info_v &ghoul2To, 
                                 int modelIndex = -1); //<--- That's it!

It is not my code and I have a lot of such things. I know that standart didn't allow such declaration, but this comment tells me that some compilers allow it.

P.S. This code from Star Wars Jedi Knight: Jedi Academy source.

Upvotes: 11

Views: 134

Answers (2)

Dmytro Ovdiienko
Dmytro Ovdiienko

Reputation: 1106

g++ v11.4 compiles that. The only thing is you should add -fpermissive parameter:

$ g++ -fpermissive x.cpp 
x.cpp:7:49: warning: default arguments are only permitted for function parameters [-fpermissive]
    7 |                                  int modelIndex = -1); //<--- That's it!
      |                                                 ^

Upvotes: 0

Murtuza Kabul
Murtuza Kabul

Reputation: 6514

Can't suggest the compiler though I've found a useful link which lists out the fixes that are required to the code to successfully compile it with GCC compiler.

http://www.lucasforums.com/showthread.php?t=203922

Hope it is useful to you.

Upvotes: 3

Related Questions