Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #70937

Re: invalid use of non-static member function

From Manfred <noname@add.invalid>
Newsgroups comp.lang.c++
Subject Re: invalid use of non-static member function
Date 2020-01-01 18:15 +0100
Organization Aioe.org NNTP Server
Message-ID <quik40$1ht8$1@gioia.aioe.org> (permalink)
References <61205cc8-816c-437b-8128-4fd0d7458fdd@googlegroups.com> <quemlp$ggv$1@dont-email.me> <qufsjm$13p8$1@gioia.aioe.org> <b8d1f108-5bb6-4c51-906e-5cd1b999854c@googlegroups.com>

Show all headers | View raw


On 1/1/2020 7:32 AM, Andrew Z wrote:
>>> OutletToggleTask is a non-static member function.
>>>
>>> As a non-static member function it takes a hidden `this` parameter,
>>> which might not be passed in the same way as other parameters. Therefore
>>> you can't convert it to pointer-to-free-function in any portable way.
>>>
>>> Additionally the construct `outlet.OutletToggleTask` is a callable
>>> expression that in itself has no type. It's silly in a very serious way:
>>> the lack of a type for it is a core language deficiency that stands in
>>> the way of easily using C++ for e.g. GUI code, or other code that
>>> requires object oriented callbacks. C# has delegates for this, and the
>>> C++ standard library has `std::function` and `std::bind`, but it really
>>> requires core language support for ease of use.
>>>
>>> One easy practical solution to your problem is to simply declare the
>>> function `static` in the class, or make it a free function.
>>>
>>>
>>> [snip]
>>>
>>> - Alf
>> There's a second problem, which is might be the one detected by the
>> compiler, although the above is definitely an error too.
>> The last argument of setup_task is expected to be an object of type
>> TickType_t, but a pointer to member function is passed instead:
>> "outlet.GetCycleTicks" should be "outlet.GetCycleTicks()"
> 
> Manfred,
>   Alf,
>   thank you for the reply.
> void setup_task(
>                  void (*DeviceTask)(void*),
>                  char* TaskName,
>                  EventGroupHandle_t eventGroup,
>                  void (*Callback_Fn)(TimerHandle_t),
>                  TickType_t cycle_ticks ) { .. }
> setup_task(
>                  outlet.OutletToggleTask,
>                  (char*)"Outlet Task",
>                  eventGroup,
>                  outlet.OutletCallback,
>                  outlet.GetCycleTicks );
> why is the outlet.GetCycleTicks is considered to be a pointer, but the eventGroup is not?

eventGroup is declared as

> EventGroupHandle_t eventGroup;

So, it is an object, not a pointer.

> 
> changing outlet.GetCycleTicks to outlet.GetCycleTicks() or a number doesn't change the compile time error. I'm still digesting what Alf said above...

This is not surprising, all of OutletToggleTask, OutletCallback and 
GetCycleTicks are non-static member functions that are used invalidly, 
although for different reasons.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

invalid use of non-static member function Andrew Z <formisc@gmail.com> - 2019-12-30 20:01 -0800
  Re: invalid use of non-static member function "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2019-12-31 06:34 +0100
    Re: invalid use of non-static member function Manfred <noname@add.invalid> - 2019-12-31 17:22 +0100
      Re: invalid use of non-static member function Andrew Z <formisc@gmail.com> - 2019-12-31 22:32 -0800
        Re: invalid use of non-static member function Manfred <noname@add.invalid> - 2020-01-01 18:15 +0100
          Re: invalid use of non-static member function Andrew Z <formisc@gmail.com> - 2020-01-01 18:49 -0800
    Re: invalid use of non-static member function Andrew Z <formisc@gmail.com> - 2019-12-31 23:03 -0800
      Re: invalid use of non-static member function "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2020-01-01 22:48 +0100
        Re: invalid use of non-static member function Andrew Z <formisc@gmail.com> - 2020-01-15 07:35 -0800

csiph-web