Page 1 of 1

Telnet in a class

Posted: Tue Mar 16, 2010 10:38 am
by ckoehler
Hello,

I moved the telnet example into a class, but cannot assign the callback methods to the command processor functions.
When I do:

Code: Select all

 CmdCmd_func = ProcessCommand;
I get:
argument of type 'int (TelnetController::)(const char*, FILE*, void*)' does not match 'int (*)(const char*, FILE*, void*)'
I can make them static and have it work, but then run into all kinds of other limitations of static methods.

Thanks!

Christoph

Re: Telnet in a class

Posted: Tue Mar 16, 2010 1:53 pm
by tod
Christoph you're in luck. I very recently wrote up a wiki entry on using class member functions in calls to the OS. In general, if you haven't already, you might want to check out the wiki. In particular the FAQ page and How To pages. If you are going to write in C++ you might find other benefit in reading the remainder of the article on moving from C to C++.

Re: Telnet in a class

Posted: Tue Mar 16, 2010 2:20 pm
by pbreed
One way to use the arbitrary void * parameter is to let you pass a class instance
the function. Then you use a static member function and cast the void * as the object then call its member function.

With a C++ class function its just a normal function that has hidden "This" pointer that gives it some way to
figure out what object its working on. In Passing this to a callback there is no way for the call back to know the "this"

You are forced to do this explicitly.

PAul

Re: Telnet in a class

Posted: Mon Mar 22, 2010 8:35 am
by ckoehler
Alright, thanks for the help guys!

Christoph