Thank you so much MiiNiPaa. Visualization helps me a lot to see what is going on:)
In line 2, x was defined to be a pointer.
In line 5, x->y is equivalent to a value (something) foo member y contains, and so
x = x-> y means x = something. Can something be a data type integer? If it is,
does that change the data type of x from a pointer to an integer?
Also, how can possibly a member of foo y, which is a pointer, contain value?
I thought only object (like foo z;) can hold attributes of a class. What syntax should I use
to let a pointer member hold attributes of a class?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
using namespace std;
struct foo{
foo *y;
int k;
};
int main(){
y->k = 5; //shows an error message. How can a pointer member y hold an integer value 5 in it?
foo z;
foo *x = &z;
x = x->y;
system("pause");
return 0;
}
|