beware of object slicing issues with Symbian descriptors
| Thu, 2005-08-25 01:14 | |
|
Hi fellow Symbians, This is a word of warning to all Symbian newbies, especially C++ newbies such as myself .Beware of object slicing with Symbian descriptors! Object slicing occurs when you try to copy (using the copy constructor for example) a bigger object into the space of a smaller one. Classic example of slicing, trying to define an object as of the type of it's base class through copying: Code: HBufC* buf = _L("hello").Alloc() ; TDesC desc = *buf ; // this is evil! That's why you should always use "TDes&" and "TDesC&" as function parameters because this avoids passed-in object getting sliced. Sliced objects will very often lead to a runtime error such as Kernel Exec 0 error. People often make this error with return types. If anyone has better examples or a better insight than what I given here then please reply to this thread. Thanks, Nikolas. If we fall down it's so we can learn to pick ourselves up. |
|






.