http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function-pointers and classes



--- Sponsor's Message --------------------------------------
Discuss Tech News as It Happens!
Keep up with the latest happenings in high tech -- FREE!
http://click.topica.com/aaaa4IbUrGczbU68iFb/technology
------------------------------------------------------------
This is for you and the other person who needed help on this.
Function pointers and class member pointers are two different entities in c++ (because class members have to deal with polymorfism, etc...)
So you can't assign to a function pointer the adress of a class member but you can assign it to a class member pointer.
(note: member pointers automaticly deal with polymorfism)
It is defined as: type (classname::*pointername)(parameters);
You can use such a pointer using the ".*" and "->*" operators.
Example:
#include <iostream.h>
class c{
public:
 int(c::*xx)(); /* pointer to member*/
 c();
 int x();
 y();
 };
c::c(){}
int c::x()
{
 return -1;
}
c::y()
{
 xx=&c::x;
 return (this->*xx)();
}
void main()
{
 c cc;
 cout<<cc.y(); /*-1*/
}
 
Unfortunatly this things are often not known.
So c++ is great after all :)
-----Original Message-----
From: Christian Gyrling <d98chgy@stud.hh.se>
To: Game Programmers Mailing List <gameprogrammer@topica.com>
Date: Tuesday, March 06, 2001 12:43 PM
Subject: Function-pointers and classes

--- Sponsor's Message --------------------------------------
Who Are the Top Dogs?
Find out about the best newsletters and discussions!
http://click.topica.com/aaaa4qbUrGczbU6XMab/TopDogs
------------------------------------------------------------
Hello all
 
First of all I give credit to all those who are taking control
of this multi-programmer-game.
 
Next I have a problem similar to that oh Josiha Avery. The thing is
how to use a function-pointer to an instance in a class.
 
int CacheSocket::create()
{
// Locally defined function pointer
// This is how the function-pointer should look to be accepted in the CreateThread
DWORD   (__stdcall *func)(void*);
 
// A function defined in the class we are currently in
func = this->ServerThread;            // THIS IS WHERE THE ERROR OCCURS
ERROR MSG
cannot convert from 'unsigned long (__stdcall CacheSocket::*)(void *)'
to 'unsigned long (__stdcall *)(void *)'
 
// Create the thread
CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)func, NULL, NULL, &ThreadId );
}
 
DWORD WINAPI CacheSocket::ServerThread( LPVOID lpParameter )
{
}
 
Please help me with this one
 
Christian Gyrling
 
 
____________________________________________________________
T O P I C A  -- Learn More. Surf Less. 
Newsletters, Tips and Discussions on Topics You Choose.
http://www.topica.com/partner/tag01
____________________________________________________________
T O P I C A  -- Learn More. Surf Less.
Newsletters, Tips and Discussions on Topics You Choose.
http://www.topica.com/partner/tag01