|
-
Jan 5th, 2001, 12:17 PM
#1
Thread Starter
Frenzied Member
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?
-
Jan 5th, 2001, 01:24 PM
#2
Monday Morning Lunatic
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;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 5th, 2001, 03:10 PM
#3
Frenzied Member
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
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|