C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do you call a regular member function from a static memb

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
aling
Guest





PostPosted: Sat Oct 29, 2005 4:07 pm    Post subject: How do you call a regular member function from a static memb Reply with quote



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

Back to top
guyarad@gmail.com
Guest





PostPosted: Sat Oct 29, 2005 4:23 pm    Post subject: Re: How do you call a regular member function from a static Reply with quote



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





PostPosted: Sat Oct 29, 2005 4:25 pm    Post subject: Re: How do you call a regular member function from a static Reply with quote



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





PostPosted: Sat Oct 29, 2005 5:38 pm    Post subject: Re: How do you call a regular member function from a static Reply with quote

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





PostPosted: Sat Oct 29, 2005 9:25 pm    Post subject: Re: How do you call a regular member function from a static Reply with quote


"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





PostPosted: Sun Oct 30, 2005 1:54 am    Post subject: Re: How do you call a regular member function from a static Reply with quote

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





PostPosted: Sun Oct 30, 2005 4:38 am    Post subject: Re: How do you call a regular member function from a static Reply with quote

why do this?
use non-static member function instead.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.