This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Pointer-to-member usage?
- From: Stefan Olsson <stefan at noname4us dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Mon, 07 Jan 2002 15:11:12 +0100
- Subject: Pointer-to-member usage?
- Organization: Noname4us
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.