Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   How do you call a regular member function from a static member function? (http://www.velocityreviews.com/forums/t449438-how-do-you-call-a-regular-member-function-from-a-static-member-function.html)

aling 10-29-2005 04:07 PM

How do you call a regular member function from a static member function?
 
How do you call a regular member function from a static member
function? Any idea?


guyarad@gmail.com 10-29-2005 04:23 PM

Re: How do you call a regular member function from a static member function?
 
By definition, you can't.
static member functions don't a particular instance of the class it
resides in.
usually, if you need an access to a specific instance, you must pass a
pointer to the instance to the static function.


TIT 10-29-2005 04:25 PM

Re: How do you call a regular member function from a static memberfunction?
 
aling sade:
> How do you call a regular member function from a static member
> function? Any idea?
>


class A {
public:
void f(){}
static void g() {
A a;
a.f();
}
};

int main() {
A::g();
return 0;
}

TIT

John Harrison 10-29-2005 05:38 PM

Re: How do you call a regular member function from a static memberfunction?
 
aling wrote:
> How do you call a regular member function from a static member
> function? Any idea?
>


Exactly the same way that you call a regular member function anywhere
else. There is nothing special about static member functions in this regard.

To call a regular member function you need an object of the appropriate
type. Then you use that to call the regular member function. E.g.

SomeObject obj;
obj.some_function();

The above code will work perfectly well in a static member function or
anywhere else.

john

Dave Townsend 10-29-2005 09:25 PM

Re: How do you call a regular member function from a static member function?
 

"aling" <ling-xiaoli@126.com> wrote in message
news:1130602040.807497.51130@z14g2000cwz.googlegro ups.com...
> How do you call a regular member function from a static member
> function? Any idea?
>


Is this a trick interview question or are you trying to write some code
dependent
on it, since this is likely to be a bad thing to do...post some code.

dave



aling 10-30-2005 01:54 AM

Re: How do you call a regular member function from a static member function?
 
Yes, this is a trick interview question .
Dave Townsend wrote:
> Is this a trick interview question or are you trying to write some code
> dependent
> on it, since this is likely to be a bad thing to do...post some code.



Xiaobin.Huang 10-30-2005 04:38 AM

Re: How do you call a regular member function from a static member function?
 
why do this?
use non-static member function instead.



All times are GMT. The time now is 08:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.