static member functions

N

Naren

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.
 
K

Karl Heinz Buchegger

Naren said:
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.
 
R

Rolf Magnus

Naren said:
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.
 
J

Jerry Coffin

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 said:
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.
 
R

Rolf Magnus

David said:
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.
 
D

David T. Croft

Jerry Coffin said:
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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top