How is friend function/class resolved ?

S

Sunny

Hi All,
In C++ , if a function or class is declared friend, then where is that
information stored? How does friend function get access to private
data of a Class?

Thanks
 
O

Obnoxious User

Sunny skrev:
Hi All,
In C++ , if a function or class is declared friend, then where is that
information stored? How does friend function get access to private
data of a Class?

Thanks

Compiler magic.
 
A

Alf P. Steinbach

* Sunny:
Hi All,
In C++ , if a function or class is declared friend, then where is that
information stored? How does friend function get access to private
data of a Class?

C++ friendship is all at compile time: it tells the compiler what access
is allowed. There is no effect at run time. No information is stored
in the program or by the program; it's all in the compiler's mind, so to
speak.
 
P

Pallav singh

Hi,,

How does a Class Come to Known that it has Given Access to Private
Member variable's ------>> to Group Certain Class's ?
what action it Need to Take when Other Non friend Class Access Its
variable ??

i want Explanation in term of Symbol Table

Thanks
Pallav
 
A

Alf P. Steinbach

* Pallav singh:
Hi,,

How does a Class Come to Known that it has Given Access to Private
Member variable's ------>> to Group Certain Class's ?
what action it Need to Take when Other Non friend Class Access Its
variable ??

i want Explanation in term of Symbol Table

Thanks
Pallav

Read the FAQ. Especially the sections about how to post.
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

How does a Class Come to Known that it has Given Access to Private
Member variable's ------>> to Group Certain Class's ?
what action it Need to Take when Other Non friend Class Access Its
variable ??

I'm not quite sure what you are asking about, but given the context of
the thread you are posting in I guess that what you are asking is how
information about access to members (private/protected/public) are
stored and enforced in the application. If this is not your question
then please clarify.

The answer is that such information is not stored in the application
itself, it's only used by the compiler while parsing the code. While
parsing the code it checks so that you only access private members from
within the class or from friends and so on. If you violate any of those
rules it generates an error and does not produce any executable. So the
access specifiers are purely compile-time constructs.
 
J

Juha Nieminen

Pallav said:
How does a Class Come to Known that it has Given Access to Private
Member variable's

How does a class know that it cannot access a variable with a
certain name of another class? How does it know if that variable
even exists?

If the compiler can give you an error if some code tries to
access the private member of another class, why wouldn't it be
anything else than completely trivial for the compiler to see
that the class is actually saying that the code is allowed to
access it?
 

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

Forum statistics

Threads
474,297
Messages
2,571,530
Members
48,252
Latest member
shilpadhussa

Latest Threads

Top