- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
C++ 标准声明于 [class.access/1] (强调我的):
A member of a class can be
- private; that is, its name can be used only by members and friends of the class in which it is declared.
- protected; that is, its name can be used only by members and friends of the class in which it is declared, by classes derived from that class, and by their friends (see [class.protected]).
- public; that is, its name can be used anywhere without access restriction.
#include <iostream>
class B {
protected:
static int const i = 1;
};
class D: public B {
public:
void f();
friend void g();
};
void D::f() {
B b;
std::cout << b.i; // OK
}
void g() {
B b;
std::cout << b.i; // error: 'i' is a protected member of 'B'
}
int main() {
D d;
d.f();
g();
return 0;
}
B::i
被声明为静态不受
[class.access/class.protected-1] 中 protected 非静态成员所特有的进一步限制的约束。这也会在
b.i
上引发相同的错误在
D::f
中访问成员函数与
g
中的相同功能。
最佳答案
这似乎是一个规范问题。我引用的部分与另一部分不同步,另一部分指定了 Clang 遵循的新正确行为(但不是 GCC 或 MSVC 令人惊讶),[class.access/base-5] (强调我的):
A member m is accessible at the point R when named in class N if
- m as a member of N is public, or
- m as a member of N is private, and R occurs in a member or friend of class N, or
- m as a member of N is protected, and R occurs in a member or friend of class N, or in a member of a class P derived from N, where m as a member of P is public, private, or protected, or
Protected member access from derived class friends
Section: 14.2 [class.access.base] Status: CD4 Submitter:Richard Smith Date: 2014-02-18
[Moved to DR at the May, 2015meeting.]
According to 14.2 [class.access.base] paragraph 5,
A member m is accessible at the point R when named in class N if
- …
- m as a member of N is protected, and R occurs in a member or friend ofclass N, or in a member or friend of a class P derived from N, where mas a member of P is public, private, or protected, or
- …
The granting of access via class P is troubling. At the least, thereshould be a restriction that P be visible at R. Alternatively, thisportion of the rule could be removed altogether; this provision doesnot appear to be widely used in existing code and such references canbe easily converted to use P instead of N for naming the member.
Notes from the June, 2014 meeting:
CWG noted that removing the friend provision would introduce anundesirable asymmetry between member functions of P and its friends.Instead, the intent is to require P to be a complete type at R.
Notes from the November, 2014 meeting:
Although the asymmetry is unfortunate, the difference between areference in a member function and a reference in a friend is that themember function concretely determines which P is in view, while thefriend could be befriended by a class that is a specialization of aclass template and thus would require instantiations that would nototherwise occur. CWG thus decided simply to eliminate the friend case.
Proposed resolution, November, 2014:
Change bullet 5.3 of 14.2 [class.access.base] as follows:
A member m is accessible at the point R when named in class N if
- …
- m as a member of N is protected, and R occurs in a member or friend ofclass N, or in a member
or friendof a class P derived from N, where mas a member of P is public, private, or protected, or- there exists…
关于c++ - 为什么派生类的 friend 不能使用 protected 成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60178872/
我想知道将来对我来说最简单的方法是什么,可以使查询既有效又不那么复杂。 我应该像这样保存双向关系吗 from_id=1, to_id=2from_id=2, to_id=1 或者只创建一个唯一的行 f
假设您有一个拥有十亿用户的社交网络。在每个用户的页面上,您想要显示该用户的 friend 数、 friend 的 friend 等等,最多五度。友谊是相互的。计数不需要立即更新,但它们应该是精确的。
public void notMyFriend(Student student1) { System.out.println("Friends who are not my frien
我有如下3个表格 用户 - id integer primary_key - user_name friend - id autoincrement primary_key - user1 integ
如何从 Friends 表中获取 friend 列表以及我 friend 的 friend 数(不包括我的 friend 数) friend 表"tbl_users_friends 字段 1:id字段
我的 MySQL 表结构是这样的。 USER int id varchar username FRIEND_LIST int user_id int friend_id 对于每个 friend 关系,
假设 a,b,c 和 b,d,e 和 c,f,g 和 a,e,g,h 是 friend 。所以 获取共同好友 b/w a&b: MATCH (me:User {username:'a'}) -[r:F
我正在开发“可能的 friend ”功能。我需要显示所有不是我 friend 的 friend 的 friend ,也不要发送我或没有我的待处理请求 FRIENDSHIPS user_id frien
如果两个用户是 friend ,我在“ friend ”表中有一个条目,如下所示: table: friends ------------------------ uid1
我有一个 friend 表,用于跟踪数据库中的关系 - 我将一个查询与子查询放在一起,该子查询从 friend 的 friend 那里获取个人资料信息 我的 friend 表如下所示 - id 双向出
我想结交 friend 的 friend 的 friend 。我得到了结果,但我不确定我的查询是否正确。我正在使用嵌套选择。 我的问题是: 查询是否正确? 我如何使用 join 执行此查询? 这是我的
假设我有一个包含 friend 属性的用户对象。这个 friends 属性是其他用户对象的数组,因此是你的 friend 。找到你 friend 的 friend 但不是你 friend 的最快算法是
我想结交我的 friend 以及 friend 的 friend ,但仅限于二级 friend 我的表结构是这样的 user_id friend_user_id 1 2 1
为了了解使用 Neo4J 建立 friend 关系的优势,我在 MySQL 数据库上创建了一张用于 Persons 的表(“Persons”,20900 个数据集): id | name --
假设我有一个名为“ friend ”的表,对于每个友谊,我添加两个条目。例如,如果用户 1 和 2 是 friend ,我们将有: uid1 uid2 ---------- 1 2 2 1
在我的图形数据库中,我有 Twig 和树叶。分支可以“包含”叶子,分支可以“包含”分支。 如何使用 Gremlin 找到与给定分支直接或间接相关的所有叶子? 我让这个在 Cypher 中工作: STA
我正在尝试使用 iPhone Facebook SDK 获取我 friend 的 friend 列表。我尝试了一种使用 FQL 和 Graph API 的方法,但在这两种情况下我都遇到了错误: "Ca
我有这个 MySQL 表: 假设我以用户 1 的身份登录,正在浏览用户 2 的个人资料。由于我们是共同的 friend (1 是 2 的 friend ,2 是 1 的 friend ),我需要回应“
我想得到我 friend 的 friend 不是我 friend 的 friend 。我有一张这样的 table :用户 friend (idUser,idUserFriend) 我在想这样的事情:
我有这个 Cypher 查询... match (p:Person{userid:8432})-[r:friends_with]->(p1:Person)-[r2:friends_with]->(p2
我是一名优秀的程序员,十分优秀!