"friend"关键字在C++中是什么意思?
What does the "friend" keyword mean in C++?
为什么在这种情况下我们需要 friend 关键字?
friend bool operator=(const Stack&<E> s, const Stack&<E> q);
这意味着允许访问Stack 对象的私有成员的 operator= 重载。
原则上,您可以在类中执行此操作,而无需使用朋友修饰符,因此签名将是
bool operator=(const Stack&<E> q) const; // The first operand would be this object
但请注意,运算符=不能在类外定义: 演示
这些"函数"不像x.y(z)
那样直接在对象上调用,其中y()
显然是函数调用,而是在执行x = z
时间接调用。
如果该函数需要访问对象的protected
或private
内部(这是很常见的事情(,则需要friend
它们,因为它们被视为对象的"外部"。
相关文章:
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 表达式"b=(b-x)&x"是什么意思?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 跟踪日志中的T.11803()是什么意思?
- 这个额外的关键字在这个 c++ 类声明中是什么意思?
- * 和 ** 在 C++ 函数声明中是什么意思?
- _T("xyz")是什么意思?
- #define Dbg(fmt,..) (0) 是什么意思? 警告:表达式无效
- 这行代码到底是什么意思?
- 在命名空间名称之前加上 :: 是什么意思?
- 从字符数组的元素中减去'a'是什么意思
- "friend"关键字在C++中是什么意思?
- 减法中的"0"是什么意思?
- 字符数组前面的加号是什么意思?
- 这里的字符串函数是什么意思