Home > Q&A > body text
1
2
3
4
5
6
7
8
9
10
11
12
13
<code>#include <iostream>
<code>#
include
<iostream>
#include <vector>
#
<vector>
#include <string>
<string>
using namespace std;
using
namespace
std;
//struct X {
// friend void f() {}//这里就没问题
//};
int main()
{
struct X {
friend void f() {}//error C2689: “f”: 不能在局部类中定义友元函数
friend void f() {}
//error C2689: “f”: 不能在局部类中定义友元函数
};
}</code>
伊谢尔伦2017-04-17 12:07:57
C and C++ functions cannot define functions inside functions.
巴扎黑2017-04-17 12:07:57
The scope of local classes is already very limited. Do you think it is necessary to declare friends? Why is there such a need?