471,612 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,612 software developers and data experts.

what does this friend declaration mean ???

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

Feb 14 '06 #1
2 2275
hs******@gmail.com wrote:
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
Feb 14 '06 #2
<hs******@gmail.com> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
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.
Feb 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

70 posts views Thread by Roy Yao | last post: by
1 post views Thread by Mike - EMAIL IGNORED | last post: by
4 posts views Thread by marco_segurini | last post: by
5 posts views Thread by Teddy | last post: by
1 post views Thread by Tony Johansson | last post: by
1 post views Thread by XIAOLAOHU | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.