#include <iostream>
#include <vector>
#include <string>
using namespace std;
//struct X {
// friend void f() {}//这里就没问题
//};
int main()
{
struct X {
friend void f() {}//error C2689: “f”: 不能在局部类中定义友元函数
};
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
C,C++函数不可以在函数内部定义函数。
局部类的作用域已经很局限了,你觉得有申明友元的必要么?为什么会有这种需求?