M
Markus S
Hi,
in this FAQ
(http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.7)
an example is given of how to 'use' a pointer to a member function. I
have trouble even implementing a subset of it:
--------- Fredmain.cpp ------------
#include "Fred.h"
typedef int (Fred::*FredMemFn)(char x, float y);
int main()
{
FredMemFn p = &Fred::f;
}
--------------------------------------------
---------------- Fred.h ------------------
class Fred {
public:
Fred();
~Fred();
int f(char x, float y);
};
--------------------------------------------
---------------- Fred.cc -----------------
#include "Fred.h"
Fred::Fred() {}
Fred::~Fred() {}
int f(char x, float y)
{
return 5;
}
--------------------------------------------
Compiling this I get:
Undefined symbols:
"Fred::f(char, float)", referenced from:
__ZN4Fred1fEcf$non_lazy_ptr in Fredmain.o
ld: symbol(s) not found
which the line 'FredMemFn p = &Fred::f;' triggers. I admit I do not
really understand the syntax of his typedef, which is why I probably
mess things up.
Thanks for any clarification.
Markus
in this FAQ
(http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.7)
an example is given of how to 'use' a pointer to a member function. I
have trouble even implementing a subset of it:
--------- Fredmain.cpp ------------
#include "Fred.h"
typedef int (Fred::*FredMemFn)(char x, float y);
int main()
{
FredMemFn p = &Fred::f;
}
--------------------------------------------
---------------- Fred.h ------------------
class Fred {
public:
Fred();
~Fred();
int f(char x, float y);
};
--------------------------------------------
---------------- Fred.cc -----------------
#include "Fred.h"
Fred::Fred() {}
Fred::~Fred() {}
int f(char x, float y)
{
return 5;
}
--------------------------------------------
Compiling this I get:
Undefined symbols:
"Fred::f(char, float)", referenced from:
__ZN4Fred1fEcf$non_lazy_ptr in Fredmain.o
ld: symbol(s) not found
which the line 'FredMemFn p = &Fred::f;' triggers. I admit I do not
really understand the syntax of his typedef, which is why I probably
mess things up.
Thanks for any clarification.
Markus