A function pointer problem...
-
void AFunction(void(*)())
{
//i am innocent
}
//A class member function
void CAClass::AFunc()
{
//I am getting an error...(it's given below)
//is it wrong to do this
//or can this be done in some other way.
AFunction(this->AFunc);
}error C2664: 'func' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
void AFunction(void(*)())
{
//i am innocent
}
//A class member function
void CAClass::AFunc()
{
//I am getting an error...(it's given below)
//is it wrong to do this
//or can this be done in some other way.
AFunction(this->AFunc);
}error C2664: 'func' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
Yeah it works with static, but why not with member functions. Sounds silly but still would like to know. Since it is also a function. Edit:Thanks a lot prakash.
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
void AFunction(void(*)())
{
//i am innocent
}
//A class member function
void CAClass::AFunc()
{
//I am getting an error...(it's given below)
//is it wrong to do this
//or can this be done in some other way.
AFunction(this->AFunc);
}error C2664: 'func' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
A function member of a class doesn't have the same prototype as a global function: there is the 'this' paramter that is passed as an implicit argument of the function (but it is transparent to the user). To avoid that, you can declare your member function as static. A static function is shared aming all instances of your class and thus doesn't require the implicit 'this' parameter. But of course, within a static function, you can only access static member of your class (because the function does not belong to a specific instance of the class).
-
A function member of a class doesn't have the same prototype as a global function: there is the 'this' paramter that is passed as an implicit argument of the function (but it is transparent to the user). To avoid that, you can declare your member function as static. A static function is shared aming all instances of your class and thus doesn't require the implicit 'this' parameter. But of course, within a static function, you can only access static member of your class (because the function does not belong to a specific instance of the class).
Good. Well said. Thanks a lot.:-D
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
void AFunction(void(*)())
{
//i am innocent
}
//A class member function
void CAClass::AFunc()
{
//I am getting an error...(it's given below)
//is it wrong to do this
//or can this be done in some other way.
AFunction(this->AFunc);
}error C2664: 'func' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
Hi, You can alsoo change
AFunction
tovoid AFunction(void(CAClass::*pFunction)())
{
//i am still innocent
}this way you can pass a pointer to a member function. This said you will need to have an object of the type CAClass available to execute the function. codito ergo sum
-
Hi, You can alsoo change
AFunction
tovoid AFunction(void(CAClass::*pFunction)())
{
//i am still innocent
}this way you can pass a pointer to a member function. This said you will need to have an object of the type CAClass available to execute the function. codito ergo sum
Hmm...Cool:cool::rose: Nice one.
BadKarma wrote:
//i am still innocent
Now that's funny...He he:laugh:
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
Yeah it works with static, but why not with member functions. Sounds silly but still would like to know. Since it is also a function. Edit:Thanks a lot prakash.
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
Owner drawn wrote:
Sounds silly but still would like to know. Since it is also a function.
no its not silly, coz it has a good logic behind it, member function has a different "hidden" signature than other functions.
-Prakash
-
Owner drawn wrote:
Sounds silly but still would like to know. Since it is also a function.
no its not silly, coz it has a good logic behind it, member function has a different "hidden" signature than other functions.
-Prakash
Mr.Prakash wrote:
no its not silly
:)
Mr.Prakash wrote:
coz it has a good logic behind it, member function has a different "hidden" signature than other functions.
Yea you are right.
-
Mr.Prakash wrote:
no its not silly
:)
Mr.Prakash wrote:
coz it has a good logic behind it, member function has a different "hidden" signature than other functions.
Yea you are right.
[Message Deleted]
-
[Message Deleted]
kdar wrote:
The functions are mangled so that they can be uniquely identified and called upon invocation
no you are wrong. mangling is nothing to do with it. mangaling is more relevant for compilers and linkers. The hidden param is the
this
param passed to the member functions.
-Prakash
-
[Message Deleted]
kdar wrote:
The functions are mangled so that they can be uniquely identified and called upon invocation
:doh:How. Can you please elaborate. It would be helpful. Edit:Where did he go:confused:Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose: -- modified at 6:47 Thursday 12th January, 2006
-
kdar wrote:
The functions are mangled so that they can be uniquely identified and called upon invocation
:doh:How. Can you please elaborate. It would be helpful. Edit:Where did he go:confused:Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose: -- modified at 6:47 Thursday 12th January, 2006
Owner drawn wrote:
Edit:Where did he go
he left coz he could not support his theory.:rolleyes:
-Prakash
-
kdar wrote:
The functions are mangled so that they can be uniquely identified and called upon invocation
:doh:How. Can you please elaborate. It would be helpful. Edit:Where did he go:confused:Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose: -- modified at 6:47 Thursday 12th January, 2006
Owner drawn wrote:
Edit:Where did he go
urgent need to go to the toilets !? :-O
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VisualCalc 3.0] -
Owner drawn wrote:
Edit:Where did he go
urgent need to go to the toilets !? :-O
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VisualCalc 3.0]:zzz:
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
-
void AFunction(void(*)())
{
//i am innocent
}
//A class member function
void CAClass::AFunc()
{
//I am getting an error...(it's given below)
//is it wrong to do this
//or can this be done in some other way.
AFunction(this->AFunc);
}error C2664: 'func' : cannot convert parameter 1 from 'void (void)' to 'void (__cdecl *)(void)'
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
i use this macro:
// call mem fn that takes a single int
#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)(int))// fns have a single int param
typedef void (CObjType::*fnType)(int);...
// holds a pointer to mem fn
fnType m_fnPtr;...
// call it
CALL_MEMBER_FN(*this, fnPtr)(5);Cleek | Image Toolkits | Thumbnail maker -- modified at 11:44 Thursday 12th January, 2006
-
A function member of a class doesn't have the same prototype as a global function: there is the 'this' paramter that is passed as an implicit argument of the function (but it is transparent to the user). To avoid that, you can declare your member function as static. A static function is shared aming all instances of your class and thus doesn't require the implicit 'this' parameter. But of course, within a static function, you can only access static member of your class (because the function does not belong to a specific instance of the class).
within a static function, you can only access static member of your class (because the function does not belong to a specific instance of the class). Unless you also pass a pointer to the object into the functiona as an additional argument, then you can access public members and functions of the class using the pointer to the class. Marriage slows down your coding, a baby slows it down even more!
-
:zzz:
Jesus Loves:rose:
--Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:
Owner drawn wrote:
ForumVisual C++ Subject:Re: Zzzz Sender:Owner drawn Date:6:56 12 Jan '06
don't sleep :)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV