Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error C2228

left of '.identifier' must have class/struct/union

The operand to the left of the period (.) is not a class, structure, or union.

The following sample generates C2228:

// C2228.cpp
int i;
struct S {
    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

You will also see this error if you use incorrect syntax when using Managed Extensions. Whereas in other Visual Studio languages, you can use the dot operator to access a member of a managed class, a pointer to the object in C++ means you have to use the -> operator to access the member:

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

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

Community Additions

© 2015 Microsoft