问题标签 [friend-function]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
65 浏览

c++ - 如果你在全局命名空间的一个类中引入一个朋友,这个朋友会被全局注入

您可以通过在封闭类中声明来将朋友声明注入命名空间:

现在函数 you( ) 是命名空间 Me 的成员。如果你在全局命名空间的一个类中引入一个朋友,这个朋友会被全局注入。

有人可以用一个例子来解释上面几行的含义。

0 投票
2 回答
511 浏览

c++ - Friend function that takes 2 classes in parameters - 'Class' not defined

I encountered some issues while working on friend functions. I want to use a friend function that uses two different classes in parameters. Here is the sample of code:

ObjectA.h:

ObjectB.h:

Both .cpp files for ObjectA and ObjectB are empty (empty constructor and destructor). Here is the main .cpp file:

This all thing sends me the following error :

And this error is pointing to this line in the ObjectB.h :

As you can see, the ObjectA.h file has been included in the ObjectB.h file. So I don't know where my error come from.

Maybe I'm using friend function in a wrong way ?

Thank you guys !

0 投票
3 回答
122 浏览

c++ - 在模板类中重载友元运算符方法

我正在尝试重载模板类的赋值('=')运算符,但我需要该operator=方法成为友元函数。

我虽然这很简单,但我做错了,因为下面的代码会导致编译错误:

错误 C2801:'operator =' 必须是非静态成员

有人可以告诉我我的方式的错误吗 - 我已经非常坚持这个:(谢谢。

0 投票
2 回答
822 浏览

c++ - Accessing protected members of derived class with CRTP

I'm using CRTP, and I have a problem with accessing the protected members of derived class.

Here is example, close to my code:

I understood, that I must use friend keyword. But I can't understand where to put it in class A< Self>. I know that I could make void _method( const B &b) public in B, but I don't want to do it. Using any keywords in B is impossible for me either!

0 投票
1 回答
675 浏览

c++ - 在 C++ 中重新定义一个类

我是 C++ 新手,遇到了一个错误问题,称为

“语义问题:'B' cB.h 的重新定义”。

我有两个类,A 和 B,其中 cA 应该通过引用处理 cB 的对象和 cA 的一个友元函数 fExample。这是代码的样子:

.h 文件 cA:

.h 文件 cB:

.cpp 文件 cB:

对我来说,似乎没有办法通过引用 cA 的友元函数来处理 cB 对象。我会知道一些解决方法,但这不是我的意图,我想学习如何以正确的方式处理这个问题。

所以提前感谢您的帮助!

0 投票
5 回答
2147 浏览

c++ - 友元函数和复制构造函数

下面显示的代码在类内定义友元函数 mag() 时无法编译,但如果在类外定义(已注释)则有效。我认为差异是由用于将参数类型从 A 更改为 B 的复制构造函数引起的。有人可以解释为什么我应该在外面定义朋友函数吗?

而且,如果B类是一个模板类(template <class T>在顶部添加),在外面定义友元函数也是行不通的。

0 投票
1 回答
1698 浏览

c++ - 显式特化不能是友元声明

编码

给出编译错误

当使用 gcc 和

在 VS2013 中编译时

我知道标准是这样说的,但是为什么呢?我想了解原因(幕后)有很多文章写着“显式专业化不能是朋友声明。”,但我不明白为什么。有任何想法吗?

0 投票
1 回答
49 浏览

c++ - 不接受前向声明

它在带有 Mingwin 的 Qt Creator 中引发以下错误。

在此处输入图像描述

为什么它会为 B 类的前向声明抛出错误?可能是我犯了一个愚蠢的错误,但我无法找到它。

0 投票
1 回答
342 浏览

c++ - 来自多个类的交友模板函数

0 投票
1 回答
181 浏览

ios - 好友列表访问问题

是否可以通过我的 iOS 应用访问 Facebook 用户的好友列表?对于接受该应用但我想要完整的朋友列表的用户,我可以毫无问题地访问。似乎在过去是可能的,现在不再可能了。

我用 :

和许可:

有没有办法访问完整的朋友列表?我必须将我的应用程序提交给 Facebook 开发团队吗?