structname is the type. So what the compiler is telling you is that you are trying to do something akin to int = 5. You want to assign to a member of the object pointed to:
#include <iostream>
using namespace std;
struct structname
{
int i;
};
int main(void)
{
structname *pointername = new structname[3];
pointername[0].i = 42;
cout << pointername[0].i << endl;
return 0 ;
}
The array notation dereferences the pointer, so the. operator is the one to use.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
i didn't know that arrays deference pointers
It's tied to the equivalence ofa[i] and *(a+i).
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314