Calling member function from pointer

This is a discussion on Calling member function from pointer within the C++ Programming forums, part of the General Programming Boards category; Nevermind, I've solved it. Sorry Solution: using boost.bind: bind(eventFunction, loginServer, _1, _2, _3)(data, dataLength, sourceSystem); I have the following problem: ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    69

    Calling member function from pointer

    Nevermind, I've solved it. Sorry
    Solution:
    using boost.bind:
    bind(eventFunction, loginServer, _1, _2, _3)(data, dataLength, sourceSystem);


    I have the following problem:

    Code:
    typedef void (LoginServer::*LoginServerMemberFunction)
       (unsigned char* data, unsigned int dataLength, SystemAddress sourceSystem);
    
    // I have a class with the following members:
    LoginServer* loginServer;
    LoginServerMemberFunction eventFunction;
    Now I want to invoke the function stored in eventFunction on the instance stored in loginServer. I think this is what mem_fun is for, but from what I could see, it can only call functions with 1 parameter.

    I tried:
    Code:
    mem_fun(eventFunction)(data,dataLength,sourceSystem);
    but got the error:
    .\LoginServerEventFunction.cpp(20) : error C2784: 'std::const_mem_fun1_t<_Result,_Ty,_Arg> std::mem_fun(_Result (__thiscall _Ty::* )(_Arg) const)' : could not deduce template argument for '_Result (__thiscall _Ty::* )(_Arg) const' from 'LoginServerMemberFunction'
    C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(595) : see declaration of 'std::mem_fun'
    .\LoginServerEventFunction.cpp(20) : error C2784: 'std::const_mem_fun_t<_Result,_Ty> std::mem_fun(_Result (__thiscall _Ty::* )(void) const)' : could not deduce template argument for '_Result (__thiscall _Ty::* )(void) const' from 'LoginServerMemberFunction'
    C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(586) : see declaration of 'std::mem_fun'
    .\LoginServerEventFunction.cpp(20) : error C2784: 'std::mem_fun1_t<_Result,_Ty,_Arg> std::mem_fun(_Result (__thiscall _Ty::* )(_Arg))' : could not deduce template argument for '_Result (__thiscall _Ty::* )(_Arg)' from 'LoginServerMemberFunction'
    C:\Program Files\Microsoft Visual Studio 8\VC\include\functional(578) : see declaration of 'std::mem_fun'
    .\LoginServerEventFunction.cpp(20) : error C2784: 'std::mem_fun_t<_Result,_Ty> std::mem_fun(_Result (__thiscall _Ty::* )(void))' : could not deduce template argument for '_Result (__thiscall _Ty::* )(void)' from 'LoginServerMemberFunction'

    Which seems to confirm that it only takes 1 argument at most (if I understand correctly).
    Last edited by C+/-; 04-03-2008 at 03:13 PM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,424
    In case anyone encounters the same problem, you can be nice enough to post your solution so they won't have the same headache as you!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 06-09-2009, 02:19 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Replies: 2
    Last Post: 04-22-2008, 12:07 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM
  5. casting a void* to a pointer to a member function
    By Sebastiani in forum C++ Programming
    Replies: 13
    Last Post: 10-15-2002, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21