hi, what is better? which different? thanks
Qt Code:
OBJ o; OBJ* pointer = o; this->pointer->.... // OR OBJ& get(); this->get(). //or OBJ* get(); this->get()->.....To copy to clipboard, switch view to plain text mode
hi, what is better? which different? thanks
Qt Code:
OBJ o; OBJ* pointer = o; this->pointer->.... // OR OBJ& get(); this->get(). //or OBJ* get(); this->get()->.....To copy to clipboard, switch view to plain text mode
Regards
Basically a reference and a pointer are pretty similar as they both point to a memory segment, the main difference, however, is that references must be initialised to reference a variable and therefore can only be NULL when forced to be null (pointers may not be initialised and be NULL instead).
Also, your first example is wrong, it must be:
&o returns the address of o which must be stored inside the pointer.
with this code you have a problem withQt Code:
OBJ* get(); this->get()->.....To copy to clipboard, switch view to plain text mode
then a object would be createt, but you wouldn't be able to access it. this would waste some memory..
regards..
aman..
Use pointers when you have to and references when you can use them.
sorry what's problem with get? it return a pointer to my object; it's an interface to access 'o' for other object... o is a private menber...Originally Posted by aMan
Regards
Use? My problem is; how do I have to declare it? which is likely? Before this I know yet I'll must use o; otherwise I don't wonder it..not?Originally Posted by jacek
Regards
oh, then it's ok..Originally Posted by mickey
@references
i assume he is thinking of the following:
see here for details..
regards..
aman..
In this case use == declare.Originally Posted by mickey
Bookmarks