Function pointers
Jul 18, 2016 at 4:27pm UTC
I created a map of function pointers, and now i want to take the pointer and pass it as a function parameter but i get error "operant of * must be a pointer".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
typedef void (PictureAlbum::*func)();
void handleInternalPath(void (PictureAlbum:: *f)());
std::map<std::string, func> links;
links["/index" ] = &PictureAlbum::showIndex;
void PictureAlbum::handleInternalPath(void (PictureAlbum:: *f)()) {
Wt::WApplication *app = Wt::WApplication::instance();
if (f != NULL) {
(*f)();
}
else {
}
}
Jul 18, 2016 at 4:33pm UTC
(this ->*f)();
And since you already have a typedef:
1 2 3
void handleInternalPath(func f);
void PictureAlbum::handleInternalPath(func f) {
Jul 18, 2016 at 4:34pm UTC
Hi,
Here's how to call a member function pointer :
1 2 3
if (f != NULL) {
(this ->*f)();
}
Jul 18, 2016 at 4:35pm UTC
Does that help you? :)
Jul 18, 2016 at 4:41pm UTC
Yes, thank you very much :D
Jul 18, 2016 at 4:42pm UTC
Good to hear :)
Topic archived. No new replies allowed.