// Illustrates precedence of field selector (.) over the // dereference operator (*). #include #include using namespace std; const int f3size = 20; typedef struct { int field1; float field2; char field3[f3size]; } rectype; typedef rectype *recPtr; void main() { rectype rec1 = {1, 3.1415f, "pi"}; recPtr r1ptr; r1ptr = &rec1; cout << (*r1ptr).field1 << endl << (*r1ptr).field2 << endl << (*r1ptr).field3 << endl << endl; // In the following code, the field selector is applied first, which produces the // quoted error message since r1ptr is not a struct variable. // // cout << *r1ptr.field1 << endl // c2228: left of '.field1' must have class/struct/union type // << *r1ptr.field2 << endl // << *r1ptr.field3 << endl // << endl; // cout << r1ptr->field1 << endl << r1ptr->field2 << endl << r1ptr->field3 << endl << endl; }