static member functions in C++ ?

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

static member functions in C++ ?

Postby Reddy » Wed Oct 15, 2003 4:18 pm

Hi,
When will we declare member functions as static in c++ ?

example :

class xyz {

public :
static int a_count();

};

here when will we declare member function "int a_count()"
as static ?

thanks
-reddy
Reddy
 

Postby Alvaro » Wed Oct 15, 2003 7:18 pm

You will make a member function static when it doesn't need an instance of the class to operate on.

Here's an explanation that I like better. A member function usually receives a hidden argument named `this', which is a pointer to an instance of the class (the object on which the method was called). Static member functions do not receive such an argument.

Is that clear, or do you need some examples?
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby Wizard » Wed Oct 15, 2003 9:02 pm

Please don't double post. I'm closing this topic, but leaving the one in general open if you want to followup.
User avatar
Wizard
Site Admin
 
Posts: 3226
Joined: Mon Sep 22, 2003 4:52 pm
Location: ON, CA


Return to For Beginners

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 2 guests