共用方式為


編譯器錯誤 C2228

'.identifier' 的左邊必須有 class/struct/union

句點左邊的操作數 (.) 不是類別、結構或等位。

下列範例會產生 C2228:

// C2228.cpp
int i;
struct S {
public:
    int member;
} s, *ps = &s;

int main() {
   i.member = 0;   // C2228 i is not a class type
   ps.member = 0;  // C2228 ps is a pointer to a structure

   s.member = 0;   // s is a structure type
   ps->member = 0; // ps points to a structure S
}

如果使用 Managed Extensions 時用了不正確的語法,您也會看到這個錯誤。 在其他 Visual Studio 語言中,您可以使用點運算符來存取 Managed 類別的成員,而 C++ 中物件的指標表示您必須使用 -> 運算符來存取成員:

錯誤: String * myString = checkedListBox1->CheckedItems->Item[0].ToString();

正確: String * myString = checkedListBox1->CheckedItems->Item[0]->ToString();