Function Pointer
-
I like to create a functionpointer on an instance of an object. I have a Universal-List that uses an array of pointer to different Rows. A row has a basic-class and all specific rows ( for example customers ) are derivated from this Class. Row -> CustomerRow In the Universal-List i like to create an array of pointer to the member-functions of the rows. The row exists already as an instance and i like to assign the functionpointer to the memberfonction of this instance... Is it possible? MSDN Help says that functionpointer must point to static functions. But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage" Thanks
-
I like to create a functionpointer on an instance of an object. I have a Universal-List that uses an array of pointer to different Rows. A row has a basic-class and all specific rows ( for example customers ) are derivated from this Class. Row -> CustomerRow In the Universal-List i like to create an array of pointer to the member-functions of the rows. The row exists already as an instance and i like to assign the functionpointer to the memberfonction of this instance... Is it possible? MSDN Help says that functionpointer must point to static functions. But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage" Thanks
baerten wrote:
But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage"
Because with a member function, there is an explicit parameter that is passed to your function: the this parameter (pointer to the instance of the class). If you post some code, maybe we can help you. Basically, what you need to do is specify that the functions in your list are members of your class (by addind a
CMyClass::
in front). But without seeing code, it is difficult.
Cédric Moonen Software developer
Charting control [Updated - v1.1] -
baerten wrote:
But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage"
Because with a member function, there is an explicit parameter that is passed to your function: the this parameter (pointer to the instance of the class). If you post some code, maybe we can help you. Basically, what you need to do is specify that the functions in your list are members of your class (by addind a
CMyClass::
in front). But without seeing code, it is difficult.
Cédric Moonen Software developer
Charting control [Updated - v1.1]void RTB::Config_Customer() { // Creates X Elements in the Internal List InternList = (BasicRow**)malloc(NumberofRows*sizeof(BasicRow*)); for(int i=0; i( ActFillRow ); // ActFillRow is a BasicRow-pointer // Creates the 8 Meta-Data Elements MetaTable= (MetaInfo*)malloc(8*sizeof( MetaInfo)); MetaTable[0].Name = "Name"; MetaTable[0].Func = &CustomerRow::SetName; // The pointer to the function that Sets the Name to the column "Name" MetaTable[1].Name = "Firstname"; MetaTable[1].Func = &CustomerRow::SetFirstname; }
The MetaTable :typedef struct MetaInfoForColumns { CString Name; ColumnSetter Func; } MetaInfo;
Column Setter:typedef void (CustomerRow::*ColumnSetter)(CString); // Functionspointer
Thanks a lot -
I like to create a functionpointer on an instance of an object. I have a Universal-List that uses an array of pointer to different Rows. A row has a basic-class and all specific rows ( for example customers ) are derivated from this Class. Row -> CustomerRow In the Universal-List i like to create an array of pointer to the member-functions of the rows. The row exists already as an instance and i like to assign the functionpointer to the memberfonction of this instance... Is it possible? MSDN Help says that functionpointer must point to static functions. But in an instance, the function is precised and accessible, so why does the fctpointer don't save the "linkage" Thanks
-
void RTB::Config_Customer() { // Creates X Elements in the Internal List InternList = (BasicRow**)malloc(NumberofRows*sizeof(BasicRow*)); for(int i=0; i( ActFillRow ); // ActFillRow is a BasicRow-pointer // Creates the 8 Meta-Data Elements MetaTable= (MetaInfo*)malloc(8*sizeof( MetaInfo)); MetaTable[0].Name = "Name"; MetaTable[0].Func = &CustomerRow::SetName; // The pointer to the function that Sets the Name to the column "Name" MetaTable[1].Name = "Firstname"; MetaTable[1].Func = &CustomerRow::SetFirstname; }
The MetaTable :typedef struct MetaInfoForColumns { CString Name; ColumnSetter Func; } MetaInfo;
Column Setter:typedef void (CustomerRow::*ColumnSetter)(CString); // Functionspointer
Thanks a lotYou're going to need a CustomerRow object to make the call to MetaTable[].Func if the function is a non-static member variable. If you make the columnsetter functions static they are going to need a CustomerRow object to access any non-static CustomerRow members. You could pass a CustomerRow reference/pointer to the function that uses the metatable to dispatch to the corresponding column setter function. Without seeing how you are using the metatable I can't give you a code example :) Mark