This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Pointer to a function forbid!!


Hello, I read the description of the gcc list and thought this might be
the more appropriate place for this.  I'm having trouble getting some
code to compile (forgive me for not knowing the exact version number,
but it's RH 7.2, I believe 2.95 or something).  What it relates to is
pointers to bound member functions.  Now not knowing exactly what that
means, I do need a way to solve this problem.   Have a a function, which
is part of Intel's UPnP SDK that needs the pointer to a function for a
callback.  I have however taken that function which it wants to use for
callback and placed it in a class.  If I pass the function as shown
below in my earlier mail to gcc-help, it gives me the following error:

ISO C++ forbids taking the address of a bound member function to form a
pointer to member function.

It seems like this would be a shortcoming of either ISO, the language,
or the compiler (or maybe I'm just ignorant and there's a better way :-)

I read this on gcc.gnu.org
(http://gcc.gnu.org/onlinedocs/gcc/Bound-member-functions.html) :
----------------------------------------------------------------------
extern A a;
extern int (A::*fp)();
typedef int (*fptr)(A *);

fptr p = (fptr)(a.*fp);

For PMF constants (i.e. expressions of the form &Klasse::Member), no
object is needed to obtain the address of the function. They can be
converted to function pointers directly: 

fptr p1 = (fptr)(&A::foo);

You must specify -Wno-pmf-conversions to use this extension"
------------------------------------------------------------------

But I can't make any sense of it.  I actually tried doing exactly what
it said but that doesn't work.  I'm showing some of the code below.
Sorry if this turns out to be a little off topic for you guys, but I
figured this might be on your level.  TIA for any comments or
suggestions.

<From my earlier posting>

Here's where I'm passing the address of gate.DeviceCallbakEventHandler()
to a function (which is part of the Intel UPnP SDK, I'll put it's
declaration below).  See, I have some code that this works with, but its
pure C.  The funtions were defined before main (I mean at the top of the
file that contains main).  They didn't use the & before the function
(which was just DeviceCallbackEventHandler), but if I don't include the
&, it says it can't find a matching function for int (*) (<paramaters>).
Candidates are int DeviceCallbackEventHandler(<parameters>).

I know there can be pointers to functions, but I'm not understanding why
it won't work here.

Muchas Gracias in advance!!!

Int main (arc, argv**){
Gate gate;
.
.
.
if ((ret = UpnpRegisterRootDevice(desc_doc_url,
&gate.DeviceCallbackEventHandler,
                                &gate.device_handle,
&gate.device_handle)) != UPNP_E_SUCCESS)
        {
		...(SNIP)
        }
.
.
.
}
///////Here is the class declaration for a Gate class.

class Gate
{
        public:
                Gate();
                ~Gate();

                int DeviceStateTableInit(char *);
                int DeviceHandleSubscriptionRequest (struct
Upnp_Subscription_Request *sr_event);
                int DeviceHandleGetVarRequest(struct
Upnp_State_Var_Request *);
                int DeviceHandleActionRequest(struct Upnp_Action_Request
*);
                int DeviceCallbackEventHandler(Upnp_EventType EventType,
void*, void*);

                PortMapList m_list;
                IPCon *m_ipcon;
                char *gate_udn;
                UpnpDevice_Handle device_handle;
};
///////AND THE following is the declaration provide in the Intel UPnP
SDK for Linux


/** {\bf UpnpRegisterRootDevice} registers a device application with
 *  the UPnP API.  A device application cannot make any other API
 *  calls until it registers using this function.  Device applications
 *  can also register as control points (see {\bf UpnpRegisterClient}
 *  to get a control point handle to perform control point
 *  functionality).
 *
 *  {\bf UpnpRegisterRootDevice} is synchronous and does not generate
 *  any callbacks.  Callbacks can occur as soon as this function
returns.
 *
 *  @return An integer representing one of the following:
 *    \begin{itemize}
 *      \item {\tt UPNP_E_SUCCESS}: The operation completed
successfully.
 *      \item {\tt UPNP_E_FINISH}: The UPnP library is already
terminated or
 *                                 is not initialized.
 *      \item {\tt UPNP_E_INVALID_DESC}: The description document was
not
 *              found or it does not contain a valid device description.
 *      \item {\tt UPNP_E_INVALID_PARAM}: Either {\bf Callback} or {\bf
Hnd}
 *              are not valid pointers or {\bf DescURL} is {\tt NULL}.
 *      \item {\tt UPNP_E_NETWORK_ERROR}: A network error occurred.
 *      \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred
writing
 *              to a socket.
 *      \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred
reading
 *              from a socket.
 *      \item {\tt UPNP_E_SOCKET_BIND}: An error occurred binding a
socket.
 *      \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting
the
 *              socket.
 *      \item {\tt UPNP_E_OUTOF_SOCKET}: Too many sockets are currently
 *              allocated.
 *      \item {\tt UPNP_E_OUTOF_MEMORY}: There are insufficient
resources to
 *              register this root device.
 *    \end{itemize} */

int UpnpRegisterRootDevice(
    IN const char *DescUrl,    /** Pointer to a string containing the
                                   description URL for this root device
                                   instance. */
    IN Upnp_FunPtr Callback,   /** Pointer to the callback function for
                                   receiving asynchronous events. */
    IN const void *Cookie,     /** Pointer to user data returned with
the
                                   callback function when invoked. */
    OUT UpnpDevice_Handle *Hnd /** Pointer to a variable to store the
                                   new device handle. */
    );




> -----Original Message-----
> From: sebastian-huber@web.de [mailto:sebastian-huber@web.de] 
> Sent: Thursday, April 11, 2002 1:42 PM
> To: Glover George
> Subject: Re: Pointer to a function forbid!!
> 
> 
> Hello,
> a bit of code might be helpful.
> 
> On Thursday 11 April 2002 20:31, you wrote:
> > Hi, I was wondering if there is ANYWAY to overcome this 
> error message 
> > with G++;
> >
> > I have to pass a pointer to a function as a parameter to some other 
> > function.  However, the funtion I need to pass is a member 
> function of 
> > a class.  When I do, g++ complains with this.
> >
> > ISO C++ forbids taking the address of a bound member 
> function to form 
> > a pointer to member function.  Cannont convert ..... (snip)
> >
> > What exactly does this mean and why not?  The function is 
> of an object 
> > that has been initialized.  It is local to main however.  
> Is it that 
> > it needs to be created with a new before I can do it or is 
> there just 
> > absolutely no way to pass a pointer to a member function?
> >
> > Thank you.
> >
> > Glover George
> > Systems/Networks Admin
> > Gulf Sales & Supply, Inc.
> > (228) 762-0268
> > dime@gulfsales.com
> > http://www.gulfsales.com
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]