c++ - Disabling "bad function cast" warning -



c++ - Disabling "bad function cast" warning -

i'm receiving next warning:

warning: converting 'void (myclass::*)(byte)' 'void (*)(byte)'

this because need pass argument fellow member function instead of ordinary function. programme running correctly.

i'd disable warning (wno-bad-function-cast doesn't work c++) or implement different way pass fellow member function.

no. take warning seriously. should rather alter code handle scenario.

pointer fellow member function(void (myclass::*)(byte)) , normal function pointer (void (*)(byte)) exclusively different. see link. cannot cast them that. results in undefined behavior or crash.

see here, how different:

void foo (byte); // normal function struct myclass { void foo (byte); // fellow member function }

now may sense that, foo(byte) , myclass::foo(byte) have same signature, why function pointers not same. it's because, myclass::foo(byte) internally resolved somewhat as,

void foo(myclass* const this, byte);

now can smell difference between them.

declare pointer fellow member function as,

void (myclass::*ptr)(byte) = &myclass::foo;

you have utilize ptr object of myclass, such as:

myclass obj; obj.*ptr('a');

c++ compiler-warnings

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -