Re: Cannot covert non-static member function to normal function?
From: Morgan Cheng (morgan.chengmo_at_gmail.com)
Date: 12/17/04
- Next message: Siemel Naran: "file >> out.rdbuf(); fails to compile, why?"
- Previous message: Luigi Napolitano: "Sort in descending order with index"
- In reply to: David Harmon: "Re: Cannot covert non-static member function to normal function?"
- Next in thread: Jonathan Mcdougall: "Re: Cannot covert non-static member function to normal function?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/
>
- Next message: Siemel Naran: "file >> out.rdbuf(); fails to compile, why?"
- Previous message: Luigi Napolitano: "Sort in descending order with index"
- In reply to: David Harmon: "Re: Cannot covert non-static member function to normal function?"
- Next in thread: Jonathan Mcdougall: "Re: Cannot covert non-static member function to normal function?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|