-
Hi,
I'm using an API function that returns a pointer to a structure.
How can I access this pointer to a structure?
I'm trying to use the following:
int pHost;
pHost = gethostbyname("blablabla");
But it doesn't seem to like it. I get the following error when compiling:
error C2440: '=' : cannot convert from 'struct hostent *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Can someone help me?
-
Code:
hostent *pHost;
pHost = gethostbyname("blahblah");
pHost->data_member (or whatever) gets you the data. Incidentally, these are equivalent:
Code:
struct me {
int A;
int B;
}
me *one;
int temp;
temp = one->A;
temp = (*one).B;
-
If you want to be technical:
. is the direct member access operator
-> is the indirect member access operator
It's useful when you are using a heirarchy of classes/structures with pointers to other classes/structures. -> can simplify things a lot:
(*(*object1).object2).object3
can be written as:
object1->object2->object3
Far less confusing :)