編譯器錯誤 C3379
'class' :巢狀類別不能有元件存取規範做為其宣告的一部分
當套用至Managed型別,例如類別或結構時, 公用 和 私用 關鍵詞會指出類別是否會透過元件元資料公開。 public
或 private
無法套用至巢狀類別,這會繼承封入類別的元件存取權。
搭配 /clr 使用時, ref
和 value
關鍵詞會指出類別受到管理(請參閱 類別和結構)。
下列範例會產生 C3379:
// C3379a.cpp
// compile with: /clr
using namespace System;
public ref class A {
public:
static int i = 9;
public ref class BA { // C3379
// try the following line instead
// ref class BA {
public:
static int ii = 8;
};
};
int main() {
A^ myA = gcnew A;
Console::WriteLine(myA->i);
A::BA^ myBA = gcnew A::BA;
Console::WriteLine(myBA->ii);
}