This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Pointer-to-member usage?


Hi!

I am aware that this is not related to the development of libstdc++, but
would appriciate input on what we are doing wrong here...

Thanks!

/Stefan

/*
 *
 *  third:~/c-source/labb$ g++ funcPoint.cpp
 * funcPoint.cpp: In member function `void B::UseFunctionPointer(int,
int)':
 * funcPoint.cpp:37: cannot convert a pointer of type `B' to a pointer
of type `A'
 * funcPoint.cpp:37: must use .* or ->* to call pointer-to-member
function in
 * `B::GetFunctionPointer() (...)'
 *
 */


#include <iostream>

using namespace std;


class A
{
    public:
        void function( int x, int y ) throw();
};


class B
{
    private:
        void (A::* GetFunctionPointer( void ) const throw() )( int x,
int y ) throw();

    public:
        void UseFunctionPointer( int x, int y ) throw();
};



void A::function( int x, int y ) throw()
{
    cout << "A::function( "<< x << ", " << y << ") throw()" << endl;
}


void (A::* B::GetFunctionPointer( void ) const throw())( int x, int y )
throw()
{
    return &A::function;
}

void B::UseFunctionPointer( int x, int y ) throw()
{
    GetFunctionPointer()(x,y);
}


int main( int argc, char* argv[] )
{
    B x;
    x.UseFunctionPointer(1,2);

    return 0;
}


--
The Heineken Uncertainty Principle:
        You can never be sure how many beers you had last night.




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