Last edited by wysota; 10th January 2010 at 15:36.
No, I don't. But you should know when to use pointers and when not to use them. Which of the following would you prefer and why?
orQt Code:
void func1() { int x; doSomething(x); }To copy to clipboard, switch view to plain text mode
Qt Code:
void func2() { int *x = new int; doSomething(*x); delete x; }To copy to clipboard, switch view to plain text mode
Normally I use pointers with vectors simply so that if I need to pass an item somewhere I can simply pass a pointer instead so avoid the object being copied for the parameter. However, starting with Qt, I find it easier to use implicitly shared classes, so the data is shared between the object unless it is modified (copy on write strategy).
Of course I'd prefer the first version of the function...There's no benefit to passing around pointers to built in types, but if that were a QByteArray or one of my own classes that is fairly large instead of a int, I'd probably use a new/delete and manage the pointers.
BTW, I just noticed that you're the owner (or admin) for Qt Centre site. Great site and love the recent upgrade. Keep up the good work!
Regards,
jthomps
hi,
it's me again i still got trouble with this vector, and i don't really get your point with what you mean with value-based?
i mean yes the class step is value based, so shouldn't i use pointers? or what you want to tell me?
my c and c++ is quite bad cause i just used java the last 2 years so i may need some generell information about, saving, in this case, steps. :/
Bookmarks