Telnet in a class

Discussion to talk about software related topics only.
Post Reply
ckoehler
Posts: 81
Joined: Sat Mar 13, 2010 9:04 pm

Telnet in a class

Post 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
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Telnet in a class

Post 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++.
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: Telnet in a class

Post 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
ckoehler
Posts: 81
Joined: Sat Mar 13, 2010 9:04 pm

Re: Telnet in a class

Post by ckoehler »

Alright, thanks for the help guys!

Christoph
Post Reply