编译器错误 C3767
“function”:候选函数不可访问
在类中定义的友元函数不应被视为它是在全局命名空间范围内进行了定义和声明。 但是,可以通过依赖参数的查找来找到它。
C3767 还可能由重大更改导致:本机类型现在在 /clr 编译中默认为私有;有关详细信息,请参阅类型可见性。
示例
以下示例生成 C3767:
// C3767a.cpp
// compile with: /clr
using namespace System;
public delegate void TestDel();
public ref class MyClass {
public:
static event TestDel^ MyClass_Event;
};
public ref class MyClass2 : public MyClass {
public:
void Test() {
MyClass^ patient = gcnew MyClass;
patient->MyClass_Event();
}
};
int main() {
MyClass^ x = gcnew MyClass;
x->MyClass_Event(); // C3767
// OK
MyClass2^ y = gcnew MyClass2();
y->Test();
};
以下示例生成 C3767:
// C3767c.cpp
// compile with: /clr /c
ref class Base {
protected:
void Method() {
System::Console::WriteLine("protected");
}
};
ref class Der : public Base {
void Method() {
((Base^)this)->Method(); // C3767
// try the following line instead
// Base::Method();
}
};