Quote from: Myndfyre on May 19, 2004, 07:22 PM
You have a pointer to a reference? Seems a bit odd. They typically serve almost the same purpose, and you probably don't need to do that. I believe a reference might be the best way to go. Of course, I could be entirely wrong.
It's not uncommon when you'll have to use a pointer to a pointer, and if you don't need the functionality a pointer provides over a reference you can use a reference for simplicity if you prefer. Personally, I prefer pointers over references, but most of the C/C++ programmers disagree with this.
Quote from: Mephisto on May 19, 2004, 08:29 PM
Quote from: Myndfyre on May 19, 2004, 07:22 PM
You have a pointer to a reference? Seems a bit odd. They typically serve almost the same purpose, and you probably don't need to do that. I believe a reference might be the best way to go. Of course, I could be entirely wrong.
It's not uncommon when you'll have to use a pointer to a pointer, and if you don't need the functionality a pointer provides over a reference you can use a reference for simplicity if you prefer. Personally, I prefer pointers over references, but most of the C/C++ programmers disagree with this.
Yeah, I know about multiple-indirection. It just seemed odd at first glance, that have a reference to a pointer. -_-
Normally references to pointers are used when you want to initialize a pointer with an address.
For example
// untested
void func(int *& p) { p = new int; }
int main() { int *ptr; func(ptr); return 0; }
Quote from: Myndfyre on May 19, 2004, 08:46 PM
Quote from: Mephisto on May 19, 2004, 08:29 PM
Quote from: Myndfyre on May 19, 2004, 07:22 PM
Quote from: Maddox on May 19, 2004, 08:49 PM
Normally references to pointers are used when you want to initialize a pointer with an address.
For example
// untested
void func(int *& p) { p = new int; }
int main() { int *ptr; func(ptr); return 0; }
You have a pointer to a reference? Seems a bit odd. They typically serve almost the same purpose, and you probably don't need to do that. I believe a reference might be the best way to go. Of course, I could be entirely wrong.
It's not uncommon when you'll have to use a pointer to a pointer, and if you don't need the functionality a pointer provides over a reference you can use a reference for simplicity if you prefer. Personally, I prefer pointers over references, but most of the C/C++ programmers disagree with this.
Yeah, I know about multiple-indirection. It just seemed odd at first glance, that have a reference to a pointer. -_-
As far as I know, a reference to a pointer is illegal. He has a pointer to a reference which is fine.
No, I think you've got those two mixed up.
My guess would be taking in a referenced pointer as a paramater is the only way to change a pointers address (the adress the pointer points to) and make it stay changed beyond scope of the function. After reading mephistos reply im now confused, so can some one clarify this.
Quote from: j0k3r on May 19, 2004, 03:50 PM
I believe two slashes is used to represent the slash character in a string, as the slash character is the escape character.
I never learned about that. that would explain why /n, /t, /0 ect only take up one char though.
Quote from: Maddox on May 19, 2004, 09:33 PM
No, I think you've got those two mixed up.
shouldnt it work either way. A reference should have the same memory address as its original
Well a pointer to a reference would be int&* which I think is illegal.
Quote from: Maddox on May 19, 2004, 09:41 PM
Well a pointer to a reference would be int&* which I think is illegal.
Now I see, I thought int&* and int*& were the same thing for some reason. Although I dont see why a reference to a pointer would be illegal, I cant argue with the compiler :)
Quote from: Maddox on May 19, 2004, 09:33 PM
No, I think you've got those two mixed up.
Yea, you're right. I got it mixed up. A pointer to a reference is illegal (&*). A reference to a pointer is legal (*&).
Quote from: Mephisto on May 19, 2004, 09:59 PM
Quote from: Maddox on May 19, 2004, 09:33 PM
No, I think you've got those two mixed up.
Yea, you're right. I got it mixed up. A pointer to a reference is illegal (&*). A reference to a pointer is legal (*&).
&* is just bad syntax for initializing a referance. its like saying:
& int myRef=whatever;
If you use the currect syntax, what stops you from assigning a pointer to a reference (of another pointer)? I hate being a C++ noob :(
Quote from: Zeller on May 19, 2004, 11:31 PM
Quote from: Mephisto on May 19, 2004, 09:59 PM
Quote from: Maddox on May 19, 2004, 09:33 PM
No, I think you've got those two mixed up.
Yea, you're right. I got it mixed up. A pointer to a reference is illegal (&*). A reference to a pointer is legal (*&).
&* is just bad syntax for initializing a referance. its like saying:
& int myRef=whatever;
If you use the currect syntax, what stops you from assigning a pointer to a reference (of another pointer)? I hate being a C++ noob :(
That's the point of a reference to a pointer? You want to assign it to another pointer, and keep a reference to it.
These discussions should probably be taken to a seperate thread. The poor guy asked for help on his program, not a discussion on the semantics of dereferencing.
In any case, a reference to a pointer makes sense. A pointer to a reference does not, because then you're only dealing with one level of indirection when you really want two.
Well if he wants to get some serious help, he should take myndfire's advice about the code tags and such. :P
Why was this topic pinned?