adress of member function (was RE: [Dev-C++] differnece between s ystem pause and cin.get())
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jaap de W. <wo...@Ne...> - 2003-02-18 09:06:00
|
-----Original Message-----
From: Ioannis Vranos [mailto:no...@ho...]
Sent: Tuesday, February 18, 2003 09:23 AM
To: Dev-C++ Mailing List
Cc: Dev-C++ Mailing List
Subject: Re: [Dev-C++] differnece between system pause and cin.get()
-------Original Message-------
From: Per Westermark
Date: =D4=F1=DF=F4=E7, 18 =D6=E5=E2=F1=EF=F5=DC=F1=E9=EF=F2 2003 =
9:42:16 =F0=EC
To: Ioannis Vranos
Cc: Dev-C++ Mailing List
Subject: Re: [Dev-C++] differnece between system pause and cin.get()
...
Member functions always have a regular address. Your description of =
call
through an offset in an array is the special case of a call to a =
virtual
method.
=3D=3D> No, no, no. Try assigning a member function to a pointer for a =
regular
function. Try to print the "address" of a member function. The standard =
does
not restrict how member functions are implemented, only that they =
cannot be
expected to be regular functions. Usually, member functions are called
through an offset of an array.
=3D=3D=3D=3D=3D> Yes, you can assign a member function to a member =
function pointer
The following program demonstrates it:
#include "stdio.h"
class Demo;
typedef bool (Demo::*CommandCallback)(const char *);
class Demo
{
public:
bool aMemberFunction(const char *);
CommandCallback GiveCallback();
};
bool Demo::aMemberFunction(const char *arg)
{
printf ("This is printed in a member funtion %s\n", arg);
return true;
}
CommandCallback Demo::GiveCallback()
{
return &Demo::aMemberFunction;
}
main()
{
Demo test;
CommandCallback Fn =3D test.GiveCallback();
(test.*Fn)("So it works");
}
Jaap de Wolff
|