class thing
{
public:
int number;
};
and i declare an object based on this class called item.
ok then here we go. If i have a function that takes the address
of an int as a paremeter such as
void doSomething(int *x)
and i wanted to pass the number from my item object id do
doSomething(&item.number).
If i had a pointer lpThing that pointed to my object item such as:
thing *lpThing;
lpThing =&item
then to use it with the function id do this:
doSomething(&lpThing->number);
but what if i had a pointer to a pointer of type thing
i.e.
thing **lplpThing;
*lplpThing = &item
to access the number id dereference like so
*lplpThing->number = 5;
but how do i pass the address of the number element in my item object
i.e
doSomething( &(*lplpThing)->number );
this is bad syntax
anyone know... i bet its something trivial liek brackets.
thanks
2DamnFunky
🔒 Locked
pointers to pointers etc
Advertisement
Original Post
hi there,
ok lets say ive got a class ''thing'' like so
when i said thats bad syntax, i meant the compiler doent like it...should that work?
You should try to do this using some more brackets, like
doSomething( &((*lplpThing)->number) );
That should work...
doSomething( &((*lplpThing)->number) );
That should work...
got it working now. Thanks for all your help
There''s another option, you can change your function to use references for it''s parameters, which might make it easier syntaxwise:
void doSomething(int &x);
Then instead of having to call the function like this:
doSomething( &(*lplpThing)->number );
this will suffice:
doSomething( (*lplpThing)->number );
And the other advantage is you don''t have to keep using
*x
inside your function everytime you want to access it''s value.
--{You fight like a dairy farmer!}
void doSomething(int &x);
Then instead of having to call the function like this:
doSomething( &(*lplpThing)->number );
this will suffice:
doSomething( (*lplpThing)->number );
And the other advantage is you don''t have to keep using
*x
inside your function everytime you want to access it''s value.
yeah i did consider doing that but unfortunately the function im dealing with is not one ive creted and defined but rather one of Direct X''s.
errrm ive only just started using classes so stuff like accessors i dont know (as of yet). I just thought a really good way to learn the ins and outs of classes would be to create a DX9 class that deals with all the various interfaces and inits.
All was going well untill i started on enumerating joystick devices. I suddenly realised that the callback function used by
IDirectInput8::EnumDevices couldnt be part of my class.
The call back function basically created and added to a linked list of DInputDevices everytime it was called and the headNode and list functions were all part of my DX9 class. Problem was i wanted to keep all these private etc and without going into the inner working of it all it meant the best way i could see of getting round this was to basically call a fucntion within the callback function that would return the address of my headNode pointer to .... drum roll..... a pointer to a pointer. Hence the question.
Oh and by the way what do you mean by ''bad coding style''... is that using accessors or something ive done?
thanks anyway for all your help.
All was going well untill i started on enumerating joystick devices. I suddenly realised that the callback function used by
IDirectInput8::EnumDevices couldnt be part of my class.
The call back function basically created and added to a linked list of DInputDevices everytime it was called and the headNode and list functions were all part of my DX9 class. Problem was i wanted to keep all these private etc and without going into the inner working of it all it meant the best way i could see of getting round this was to basically call a fucntion within the callback function that would return the address of my headNode pointer to .... drum roll..... a pointer to a pointer. Hence the question.
Oh and by the way what do you mean by ''bad coding style''... is that using accessors or something ive done?
thanks anyway for all your help.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement