|
|
Classification: |
C++ |
Category: |
Base |
Created: |
09/20/2002 |
Modified: |
12/06/2002 |
Number: |
FAQ-0825 |
Platform: |
Not Applicable |
|
Question: TBufC is described as a non-modifiable buffer descriptor. Since its buffer is private, its Ptr() method returns a const pointer
and it has no methods which allow its data to be modified after initialisation, is it safe to assume that the data of a TBufC
is immutable?
Answer: No it is not. TBufC has a Des() method (as does HBufC) which returns a TPtr, so allowing any (so-called) non-modifiable buffer descriptor to be exchanged for a modifiable one. The "C" really indicates
no more than an intention about how the descriptor should be used. So if you find yourself using the Des() function, you should probably ask yourself:
- if it's for a TBufC declared in your own code, should you not rather have declared a TBuf?
- if it's for a descriptor declared in another class, are you conforming to the intention of the designer of that class for
this descriptor's data not to be modified?
|
|
|