what does this friend declaration mean ???

H

hsharsha

Consider the below code:

int main(void)
{
class inner
{};
friend class inner; /* what does this signify???? */
return 0;
}

what does 'friend class inner' mean in the above code. its not inside a
class.......

This code is compilable in microsoft c++ compiler 12.0 and 13.0 but
not compilable in gnu c++ compiler. gnu c++ compiler will report the
following error:

`friend' can only be specified inside a class
 
B

benben

Consider the below code:

int main(void)
{
class inner
{};
friend class inner; /* what does this signify???? */
return 0;
}

what does 'friend class inner' mean in the above code. its not inside a
class.......

Nothing. It's illegal.
This code is compilable in microsoft c++ compiler 12.0 and 13.0 but
not compilable in gnu c++ compiler. gnu c++ compiler will report the
following error:

Ms C++ compiler 12 and 13 are very old. Avoid using them.
`friend' can only be specified inside a class

It says what needs to be said.

Regards,
Ben
 
J

Jim Langston

Consider the below code:

int main(void)
{
class inner
{};
friend class inner; /* what does this signify???? */
return 0;
}

what does 'friend class inner' mean in the above code. its not inside a
class.......

This code is compilable in microsoft c++ compiler 12.0 and 13.0 but
not compilable in gnu c++ compiler. gnu c++ compiler will report the
following error:

`friend' can only be specified inside a class

The gnu c++ compiler is correct. The Microsoft c++ compiler is wrong.

friend is used inside a class to state what other classes/functions can
access it's private members.
 

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,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top