English 中文(简体)
朋友与朋友之间的区别是什么?
原标题:what is the difference between friend function and friend class?

朋友与朋友之间的区别是什么? 以及应当如何使用朋友的关键词?

最佳回答

简言之,一个等级和一个职能。 就职能而言,只有一项职能能够接触到私人成员。 对于一个班级,整个班级及其所有职能都能够接触友好班的私人成员。

朋友的关键词被用来允许接触私人数据成员。 有时,你可能需要一个助手班或一个补习班,以接触不同类别的私人成员。 就职能而言,一个常见的例子就是经营者超负荷工作。 或许,你想要超载+运营商。 您可以将操作员+功能宣布到该类别之外(因此可以不必标出),并且需要查阅私人类别的数据。

查阅,该网址详细描述这两个网站及其使用方式。

问题回答

Friend function

  1. The friend keyword is used for declaration.
  2. While writing definition of function, the friend keyword is not required.
  3. Through a friend function, we can allow outside functions to access the class members.

Friend class

  1. For the declaration of a friend class, the friend keyword is used: friend class a;
  2. While writing a class, the friend keyword is not required.
  3. With a friend class we can access the members of one class into another.

A friend function is used for accessing the non public member of a class.A class can allow non-member function and other classes to access its own private data by making them friend A Friend class has full access of private data members of another class without being member of that class.

友好的关键词也可以使用功能和等级。

这意味着,如果宣布某类人员为朋友,则可以接触宣布为朋友的所有数据成员(私人和公共)。

我已经用我的博客中的例子解释了他们之间的区别:。 朋友与朋友之间的差别

(1) 用户功能用于获取使用成员功能的私人数据变量的同一类别。

2)u 可以把朋友的职能放在主要职能中,没有任何目标,但只要求成员履行职务,才需要创建同一类的目标。

3) 朋友的职能可以被视为非成员的职能,但成员的职能不被视为非成员职务。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签