473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2399
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roy Yao | last post by:
Why the following code let my compiler complain an overloaded function Init()? // code begin template<class T> class BicircularList { template<class T> class Iterator; template<class T> class...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
1
by: Mike - EMAIL IGNORED | last post by:
Are static friend functions allowed? I tried this today with gcc-3.2 without success. The function was not a class member. The friend statement was interpreted as meaning "extern", and this was...
20
by: Sam | last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I think it's consistent with every rule but always got compiling errors that I don't understand. The code include 5 files as...
2
by: Yu Lianqing | last post by:
Hi, all I am writing an overloading operator >> function for a template class and can't make it right. G++ 3.2 (Redhat8.0) gives the following errors: g++ -c list.cxx In file included from...
4
by: marco_segurini | last post by:
Hi, the following test program shows a solution to a problem I have had. Now, this test program is compiled and linked by VS2003 and g++ while Comeau-on-line-compiler fails with this messages:...
5
by: Teddy | last post by:
Hello all consider the class Date declaretion below: class Date { public: Date(); Date(int year, int month, int day); Date(const string&); int getYear() const;
1
by: Tony Johansson | last post by:
Hello experts! Assume I have this class definition of class ListElem. I'm a bit unsure how to interpret when you put friend declaration in public, protected and private section of a class...
4
by: fdmfdmfdm | last post by:
I have the following code: #include <iostream> #include <cstdlib> #include <cassert> using namespace std; template <class T> class Stack{ public: enum{DefaultStack = 10, EmptyStack = -1};
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.