I confess that it still causes me stress to return a CString. I know better
and I do it, but the old habits are hard to break. Or course with C# there
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
If this were an issue, it would fall into the exotic-situation category; I
don't think the
OP was even considering this. What I see all too often is people forcing
MFC to behave
like K&R C on the PDP-11 in 1975, by using techniques to get back to the
types they know
and love, no matter how inappropriate those types are for ordinary
programming. The most
common area of failure here is the string types.
joe
On Thu, 26 Jun 2008 15:54:36 -0500, "Doug Harrison [MVP]" <dsh@mvps.org>
wrote:
On Thu, 26 Jun 2008 15:43:20 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:
So why are you not returning a CString? It is a common error to think
that you have to
return LPCTSTR types when the sensible thing is to return a CString.
This mistake is most
commonly made when a string value has to be returned from a class that
has a CString type.
Generally, you can assume that LP[C]TSTR is fairly uncommon, used in only
slightly-exotic
circumstances. Even API calls that require LPCTSTR can use a CString
type. LPTSTR is
most commonly used when you need a GetBuffer pointer. My most common use
is at the
interface level to APIs, and it certainly appears to be inappropriate as
a way to return a
pointer to a CString value from a class.
(And if you're thinking of "efficiency", then you really don't understand
the issues about
efficiency. How much does it matter when you are about to log a message,
pop up a
MessageBox, etc., if the code is 20us slower?)
joe
Efficiency is not the only issue for returning or passing objects of class
types. Exception safety is another concern. (Of course, the
reference-counting CString does should make that a non-issue, though
aren't
there some conditions in which a CString is considered "locked" to
reference counting?)
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm