編譯器錯誤 C2327
'symbol': 不是類型名稱、靜態或列舉值
巢狀類別內的程式代碼會嘗試存取不是類型名稱、靜態成員或列舉值之封入類別的成員。
使用 /clr 編譯時,C2327 的常見原因是屬性名稱與屬性類型相同。
下列範例會產生 C2327:
// C2327.cpp
int x;
class enclose {
public:
int x;
static int s;
class inner {
void f() {
x = 1; // C2327; enclose::x is not static
s = 1; // ok; enclose::s is static
::x = 1; // ok; ::x refers to global
}
};
};
如果類型的名稱由成員的名稱隱藏,也可能會發生 C2327:
// C2327b.cpp
class X {};
class S {
X X;
// try the following line instead
// X MyX;
X other; // C2327, rename member X
};
在此情況下,C2327 也可以引發,您必須完整指定 參數的數據類型:
// C2327c.cpp
// compile with: /c
struct A {};
struct B {
int A;
void f(A a) { // C2327
void f2(struct A a) {} // OK
}
};
下列範例會產生 C2327:
// C2327d.cpp
// compile with: /clr /c
using namespace System;
namespace NA {
public enum class E : Int32 {
one = 1,
two = 2,
three = 3
};
public ref class A {
private:
E m_e;
public:
property E E {
NA::E get() {
return m_e;
}
// At set, compiler doesn't know whether E is get_E or
// Enum E, therefore fully qualifying Enum E is necessary
void set( E e ) { // C2327
// try the following line instead
// void set(NA::E e) {
m_e = e;
}
}
};
}
下列範例顯示當屬性的名稱與屬性類型相同時,C2327:
// C2327f.cpp
// compile with: /clr /c
public value class Address {};
public ref class Person {
public:
property Address Address {
::Address get() {
return address;
}
void set(Address addr) { // C2327
// try the following line instead
// set(::Address addr) {
address = addr;
}
}
private:
Address address; // C2327
// try the following line instead
// ::Address address;
};