473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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?

Oct 29 '05 #1
6 1446
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.

Oct 29 '05 #2
TIT
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
Oct 29 '05 #3
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
Oct 29 '05 #4

"aling" <li*********@126.com> wrote in message
news:11*********************@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
Oct 29 '05 #5
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.


Oct 30 '05 #6
why do this?
use non-static member function instead.

Oct 30 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dmitry.freitor | last post by:
Why would someone call a non-static provate member function from another non-static member function of the same class via the this pointer? Thanks. DF
1
by: zx.zhangxiong | last post by:
Dear all, I'm puzzled about the usage of class member function. Any help would be appreciated. class Account { ...
7
by: Ook | last post by:
What am I doing wrong? This code gives a compile error: 'SortedList<T>::insert' : illegal call of non-static member function. I've tried several variations of this, but keep getting the same error....
10
by: shanknbake | last post by:
I'm getting the following compile-time error: error C2352: 'Person::getCount' : illegal call of non-static member function Here is my getCount function declaration:...
2
by: mahesh | last post by:
Can anyone direct me to the place where i find the solution for the error message "cannot call member function 'X' without object"??? thanks in advance
20
by: Bruce. | last post by:
I am trying to call a member function through a pointer to it and can't get the syntax exactly right. This compiles with an error C2064, term does not evaluate to a function taking 1 argument.. ...
3
by: zaeminkr | last post by:
I have class member data which is a pointer to class member function. However, I'm fail to compile the code. What is the correct grammar to make a function call by using static member data...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
12
by: aaragon | last post by:
I have this scenario: several arrays for which I have their fixed values at compilation time. Now, at runtime I need to access a specific array depending on an integer but I want to avoid if and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.