| View previous topic :: View next topic |
| Author |
Message |
aling Guest
|
Posted: Sat Oct 29, 2005 4:07 pm Post subject: How do you call a regular member function from a static memb |
|
|
How do you call a regular member function from a static member
function? Any idea?
|
|
| Back to top |
|
 |
guyarad@gmail.com Guest
|
Posted: Sat Oct 29, 2005 4:23 pm Post subject: Re: How do you call a regular member function from a static |
|
|
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.
|
|
| Back to top |
|
 |
TIT Guest
|
Posted: Sat Oct 29, 2005 4:25 pm Post subject: Re: How do you call a regular member function from a static |
|
|
aling sade:
| Quote: | 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
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Sat Oct 29, 2005 5:38 pm Post subject: Re: How do you call a regular member function from a static |
|
|
aling wrote:
| Quote: | 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
|
|
| Back to top |
|
 |
Dave Townsend Guest
|
Posted: Sat Oct 29, 2005 9:25 pm Post subject: Re: How do you call a regular member function from a static |
|
|
"aling" <ling-xiaoli (AT) 126 (DOT) com> wrote
| Quote: | 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
|
|
| Back to top |
|
 |
aling Guest
|
Posted: Sun Oct 30, 2005 1:54 am Post subject: Re: How do you call a regular member function from a static |
|
|
Yes, this is a trick interview question .
Dave Townsend wrote:
| Quote: | 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.
|
|
|
| Back to top |
|
 |
Xiaobin.Huang Guest
|
Posted: Sun Oct 30, 2005 4:38 am Post subject: Re: How do you call a regular member function from a static |
|
|
why do this?
use non-static member function instead.
|
|
| Back to top |
|
 |
|