PDA

Click to See Complete Forum and Search --> : using a pointer to a structure..


softwareguy74
Jan 5th, 2001, 11:17 AM
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?

parksie
Jan 5th, 2001, 12:24 PM
hostent *pHost;

pHost = gethostbyname("blahblah");

pHost->data_member (or whatever) gets you the data. Incidentally, these are equivalent:

struct me {
int A;
int B;
}

me *one;
int temp;

temp = one->A;
temp = (*one).B;

HarryW
Jan 5th, 2001, 02:10 PM
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 :)