Re: Cannot covert non-static member function to normal function?

From: Morgan Cheng (morgan.chengmo_at_gmail.com)
Date: 12/17/04


Date: Fri, 17 Dec 2004 17:44:26 +0800
To: David Harmon <source@netcom.com>

Thanks for you clarification.
But I think that, from semantic perspective, the reason is that each
non-static member function has an implicit parameter of pointer to
"this". As a result,
If "int foo(int data);" is declared as a member function, its signature
is actually different from normal function because it has one more
parameter.

David Harmon wrote:
> On Fri, 17 Dec 2004 10:02:53 +0800 in comp.lang.c++, Morgan Cheng
> <morgan.chengmo@gmail.com> wrote,
>
>>I am wondering why C++ doesn't allow non-static member function to be
>>coverted into normal function.
>
>
> A non-static member function must be called in such a way that it is
> passed a 'this' pointer. Calling a normal function cannot do that.
>
> This issue is covered in Marshall Cline's C++ FAQ. See the topic
> "[33.2] How do I pass a pointer-to-member-function to a signal
> handler, X event callback, system call that starts a thread/task,
> etc?" It is always good to check the FAQ before posting. You can
> get the FAQ at:
> http://www.parashift.com/c++-faq-lite/
>



Relevant Pages

  • Re: Function Pointer Query
    ... Note that pointer to member function is incompatible with regular ... needs a callback, you are sadly out of luck. ... void EnumWindows; ...
    (microsoft.public.vc.language)
  • Re: Why pointer to member function?
    ... I want a simple,clean,cheap way that can save the member function ... fixed for any type of closure. ... don't want to save a pointer to a pointer to a member function ... the boost lib does prove that I'm not wrong on this. ...
    (comp.lang.cpp)
  • Re: c[++] pointer question
    ... A pointer is a variable that contains a memory address. ... The above are member variables. ... A constructor is a special member function that is meant to initialize ... In modern C++ the initialization is better done via an initializer list, ...
    (comp.lang.cpp)
  • Re: A C++ Whishlist
    ... > You invoke undefined behaviour and the compiler is free to do as it ... > calls a member function via a NULL pointer. ... > means that it doesn't invoke undefined behaviour, ... > undefined behaviour until you invoke a member function via a NULL ...
    (comp.lang.cpp)
  • Re: Static member functions in VC
    ... What I want to achieve is NON static member function to be assigned as ... It is exactly right that it HAS TO contain pointer to an object itself. ... as Microsoft hasn't implemented any common solution of this problem in VC++ ... > instance pointer and a pointer to member function, ...
    (microsoft.public.vc.language)