Connecting Tech Pros Worldwide Forums | Help | Site Map

again on function pointer

enzo
Guest
 
Posts: n/a
#1: Jul 22 '05
hi all,

could anyone explain me why this doesn't compile??

#include<iostream>

using namespace std;
class test;

class messenger
{
public:
messenger(void(test::*p_f)() = 0)
: m_f(p_f)
{
}

void
call()
{
(*this.*m_f)();
}

void
set(void(test::*p_f)())
{
m_f = p_f;
}

void (test::*m_f)();
};

class test
{
public:
test()
: m(0)
{
m.set(&test::f);
}

void f()
{
cout << "Hallo! " << endl;
}

messenger m;
};


int
main()
{
test a;
a.m.call();
return 1;
}

thanks
e
~

David Harmon
Guest
 
Posts: n/a
#2: Jul 22 '05

re: again on function pointer


On 30 Jan 2004 01:55:24 -0800 in comp.lang.c++,
principeoussama@yahoo.com (enzo) was alleged to have written:[color=blue]
>could anyone explain me why this doesn't compile??[/color]

No fair asking about code that doesn't compile without
quoting the error message.
[color=blue]
>class messenger
>{
>public:[/color]
....[color=blue]
> void
> call()
> {
> (*this.*m_f)();
> }[/color]
....[color=blue]
> void (test::*m_f)();[/color]

m_f points to a member function of class test.

(*this) is an object of class messenger.

You cannot call a test member function on a messenger object.

Closed Thread