cast/assignement operators

J

John Doe

Hi,

I am trying to replace the use of the Windows CString class by a
compatible one (CStdString) using std::string , the problem is I cannot
do the following thing :

A)
CString strFullPath;
CStdString& str = strFullPath;

or this :

B)
CStdString strFolder;
m_treeFolder.GetItemText(hItem, strFolder);
with GetItemText defined like this :
BOOL GetItemText(HTREEITEM hItem, CString& strText) const;


The question is in A) case when I assign a CStdString& with a CString
which operator is called, the assignment one, a cast ?

In B) same question should I declare a cast operator ? an assignement one ?

Final question what should I declare to make A) and B) possible ?
 
J

John Doe

Sam said:
No operator gets called. A reference is, essentially, a pointer. It must
reference, or point, to something.
It can't reference/point to an object of a different class.
Is it true even if CStdString has exactly the same method signatures as
a CString ?
 
J

Jim Langston

John Doe said:
Is it true even if CStdString has exactly the same method signatures as a
CString ?

Yes, it is true because CStdString is NOT a CString. They are two different
classes.

But, if you are trying to replace CString with CStdString why do you have
CString in your code anyway? Replace it with CStdString. Although I would
suggest you drop CStdString all together and just go with std::string.
 
R

.rhavin grobert

Having said all this, after going through something similar myself,
converting a bunch of code that used MS's gawdawful CString,

just curious: what's wrong with CString?
 
J

John Doe

..rhavin grobert said:
just curious: what's wrong with CString?
Have you ever tried to write code on multiplatform ?
Windows, Windows CE, Symbian, iPhone, ...
I think you have you answer.
and the raw std::string is really limited compared to CString that's why
I am using CStdString.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top