編譯器錯誤 C2819
類型 'type' 沒有多載成員 'operator ->'
您必須定義 operator->()
才能使用此指標作業。
下列範例會產生 C2819:
// C2819.cpp
// compile with: /c
class A {
public:
int i;
};
class B {};
void C(B j) {
j->i; // C2819
}
class D {
A* pA;
public:
A* operator->() {
return pA;
}
};
void F(D j) {
j->i;
}
使用參考類型的C++堆棧語意時,也會發生 C2819。 下列範例會產生 C2819:
// C2819_b.cpp
// compile with: /clr
ref struct R {
void Test() {}
};
int main() {
R r;
r->Test(); // C2819
r.Test(); // OK
}