gilad wrote:
hi,
I would like to get the address of a class method in an instance.
Class method (a member function) has its address independent from
any instance. Or, most likely, I didn't understand what it is you
need.
>
In the following sample the third like access the method.
I am not sure I understand the preceding sentence.
how can I
get the address into a long variable - something like -
long addr = B->*local_method ... (this does not work)
You would need to use 'reinterpret_cast' to get the address of
a member function into an integral variable, *IF* there is some
integral type large enough to store the member address.
>
class BCls {
public:
void method(void ) {
Drop the 'void' between the parentheses. Makes your code look C.
int k = 9;
};
BCls() { };
~BCls() {};
Drop the trailing semicolons after function bodies. Without
them the code is more readable.
};
void main()
int main() // there is no 'void main' in C++
{
BCls * B = new BCls();
void (BCls::*local_method)(void) = &BCls::method;
(B->*local_method)();
}
Once you replace 'void main' with 'int main', your code becomes
valid C++.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask