0

I have created a function pointer

void(Status::*StatusFormImageChange)(bool);

Now I want to call it with an argument. But when I try to call with

StatusFormImageChange(true);

I get an error

The expression doesn't give a function which takes one argument

Christoph
  • 542
  • 4
  • 24
  • Sorry, but that doesn't help me. I think the links says that it should be called with *(StatusFormImageChange)(true); but that doen't worl either. – Christoph Aug 12 '16 at 11:23
  • 1
    The link says you need to call it with an object of the relevant class, like this `(my_status.*StatusFormImageChange)(true)`. – TartanLlama Aug 12 '16 at 11:29
  • And why does it work for pointers which don't get any arguments without any object like StatusFormImageChange; ? – Christoph Aug 12 '16 at 11:31
  • Do you mean non-member function pointers? That works because they don't require an object to operate on. Think about what it would mean to call a member function without an object; it doesn't make sense. – TartanLlama Aug 12 '16 at 11:34
  • Ok. How is a non-member function pointer called with arguments? – Christoph Aug 12 '16 at 11:37
  • When I see this: http://www.cprogramming.com/tutorial/function-pointers.html it is straightforward. He is calling it wight foo( 2 ); but I don't understand why that doesn't work with my code. – Christoph Aug 12 '16 at 11:50
  • @Christoph Because your code is calling a member function. You need to do that with an object, just like when you're calling a member function normally by name. – Barmar Aug 12 '16 at 12:01
  • So sorry. But I don't get that. Why is there such a difference between NoArgument/Argument calls? For the member function with no passed arguments, I don't need any objects. That makes no sense. When I implement functions that can be called without any object reference, I always can implement functions with arguments too. Or am I wrong? – Christoph Aug 12 '16 at 12:06
  • @Christoph Calling a member function pointer with no arguments looks like `(obj.*fn)();`. Contrast with simply `fn;` : the latter simply names the member function pointer, but does nothing at all : it's not a function call. – Quentin Aug 12 '16 at 12:32

0 Answers0