C/C++
Because * is a dereference operator that returns an object under a given pointer and operator & is a reference operator that returns a pointer to a given object.Function ProcessCats1 expects an object of type Cat not a pointer, why must I useinstead ofQt Code:
ProcessCats1("tofi",*tofi,"white");To copy to clipboard, switch view to plain text modeQt Code:
ProcessCats1("tofi",&tofi,"white");To copy to clipboard, switch view to plain text mode
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
See above.Same analogy with function ProcessCats2 which requires a pointer to object Cat and I do, but smuki is an object, why do I need the "&" meaning "the value at address".Qt Code:
ProcessCats2("smuki",&smuki,"no color");To copy to clipboard, switch view to plain text mode
It's a matter of understanding heap-allocated objects and stack-allocated objects rather than scopes. Every local variable is destroyed when it goes out of scope by unwinding the stack. Heap-based variables (allocated using new operator) are never destroyed automatically.I can delete object created on the heap like this , but how do I delete smuki in the scope of same function if I need (I know it gets destroyed when out of scope).
No, delete takes a pointer to the object that is to be deleted. So it is the object that gets deleted and not the pointer. The pointer will be freed when the scope of its declaration ends.When I do I delete just the pointer to value of smuki
No, but you can still access the pointer, so I can still access object smuki right?![]()
Bookmarks