By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

static member functions

P: n/a
Hello Grp,
Correct me if I am wrong.
static member functions can act only on static member varaibles.It can
accessed by using the name of the class.
Then why is there an access controller.

what does a private static member function mean?

Thaanx in advance for any advice
Rgds,
Naren.
Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a


Naren wrote:

Hello Grp,
Correct me if I am wrong.
static member functions can act only on static member varaibles.It can
accessed by using the name of the class.
Then why is there an access controller.

Why should there not be?
what does a private static member function mean?


That it can be called from ordinary member functions of
the same class only.

Eg. It can be used for helper functions, which don't need
access to object internal data.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #2

P: n/a
Naren wrote:
Hello Grp,
Correct me if I am wrong.
static member functions can act only on static member varaibles.
No. A static member function isn't called for a specific object, so it
doesn't have a "this" pointer or an object to operate on. If you crate
an object locally, reference an external object or get one passed as
parameter, you can access anything from it.
It can accessed by using the name of the class.
Yes.
Then why is there an access controller.
Access control is unrelated to static member functions.
what does a private static member function mean?


That it's a static function that can only be called by member functions
of the same class and by friends of that class.

Jul 19 '05 #3

P: n/a
In article <bg**********@ns2.fe.internet.bosch.com>,
na*************@in.bosch.com says...
Hello Grp,
Correct me if I am wrong.
static member functions can act only on static member varaibles.
Okay, you're wrong. A static member function can act on a non-static
member variable as long as it has an instance of the object to act on.
Also consider something like a static member function being used as a
call-back function. Nothing outside the class needs access to it by
name, but it has to be a static function to have the correct type.
It can
accessed by using the name of the class.
Yes. And so?
Then why is there an access controller.
To control access, of course. <G>
what does a private static member function mean?


It means the name is only visible to other class members, just like
private does with anything else.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 19 '05 #4

P: n/a

"Jerry Coffin" <jc*****@taeus.com> wrote in message
news:MP************************@news.clspco.adelph ia.net...
In article <bg**********@ns2.fe.internet.bosch.com>,
na*************@in.bosch.com says...
Hello Grp,
Correct me if I am wrong.
static member functions can act only on static member varaibles.


Okay, you're wrong. A static member function can act on a non-static
member variable as long as it has an instance of the object to act on.
Also consider something like a static member function being used as a
call-back function. Nothing outside the class needs access to it by
name, but it has to be a static function to have the correct type.


The function would look like:

void method(CYourClass* pYourClass)
{
pYourClass->PublicMember = 0;
}

Only public members can be accessed(unless it is declared as a "friend" but
that gets into something else).
Jul 19 '05 #5

P: n/a
David T. Croft wrote:
> Correct me if I am wrong.
> static member functions can act only on static member varaibles.


Okay, you're wrong. A static member function can act on a non-static
member variable as long as it has an instance of the object to act
on. Also consider something like a static member function being used
as a
call-back function. Nothing outside the class needs access to it by
name, but it has to be a static function to have the correct type.


The function would look like:

void method(CYourClass* pYourClass)
{
pYourClass->PublicMember = 0;
}

Only public members can be accessed(unless it is declared as a
"friend" but that gets into something else).


If the above is supposed to be a static member function of CYourClass,
then this is not true. Making a member static or not is in no way
related to access rights. It's a member function, so it can access all
the members of the class.
Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.