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

what does this friend declaration mean ???

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
<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.