C++ typedef member function signature syntax

后端 未结 5 1722
清酒与你
清酒与你 2020-12-23 17:22

I want to declare type definition for a member function signature. Global function typedefs look like this:

typedef int (function_signature)(int, int);
typed         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 17:47

    Well basically it can't work (at least I know no way using g++); Using borland c++ compiler there would be the __closure keyword.

    The reason why it does not compile is, that sizeof the functionpointer (on a x86 machine) occupies always <<32bits>>; but if you want to point to a class (interface) signature, the sizeof has to be 64bit: 32 bit for the this pointer (as the class interface is in the memory only once) and 32 bit for the actual function

    But the __closure keyword is a bcb language 'hack' not standardized...

提交回复
热议问题