Suppose to have:
struct Tstudent
{
string name, surname;
int matriculation_num;
};
struct Tnode
{
Tstudent* student;
Tnodo* next;
} L;
I want to deference that "student" pointer. For example, I tried with:
*(L->student).matriculation_num
but it not worked, as terminal says:
listaStud.cc:228: error: request for member �matriculation_num' in �L->Tnodo::student', which is of non-class type �Tstudent*'
So how can I access to data contained in "student" from L ?
Yeah, above... So you under stand. L is NOT a pointer, thus, the "." notation is how you "navigate" into that structure. The student member in L IS a pointer, thus, the "->" notation (which is equal to "(*x).") navigates that.
If you had:
struct test
{
int data;
};
struct test2
{
struct test *ptr;
struct test nonPtr;
};
void main()
{
struct test2 test2Data;
struct test2 *test2Ptr = &test2Data;
test2Data.ptr = &test2Data.nonPtr;
test2Data.nonPtr.data = 42;
test2Data.ptr->data = 42;
test2Ptr->nonPtr.data = 42;
test2Ptr->ptr->data = 42;
}
You can see the pattern.
1 Like
Glad to see you too, bigearsbilly.
Thank you guys.
glad to help Luke!
pointers are hard to grasp.