type cast converting chars to CSring

G

Guest

I have a older C++ project from a pre .net Visual studio. I just want it to
run "the old way" in the new environment, not yet wanting to do any dotnet
stuff. Several conversions that worked before are errors now
The code
CString strAsciiLocation = (GetColumn() + 'a' - 1);
strAsciiLocation += (GetRow() + '0');
generates the error

c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\LocationOnBoard.cpp(207): error C2593: 'operator +=' is ambiguous
For the second line GetColumn and GetRow both return integers for example if
both returned 1 I wanted the string a1 for strAsciiLocation.

And
return CString('a' + FromLocation.GetColumn() -1)
+ CString('1' + FromLocation.GetRow() -1)
+ CString('a' + ToLocation.GetColumn() -1)
+ CString('1' + ToLocation.GetRow() -1);
generates four errors of the type
c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\Board.cpp(440): error C2440: 'type cast' : cannot convert from
'int' to 'ATL::CStringT<BaseType,StringTraits>'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
Although the first line of the first example doesn't generate an error.
Any suggestions on how to make these kinds of conversions in the new
environment?
 
G

Guest

Silly me just put char() around everything and the world is beautiful again.
For example
strAsciiLocation += char(GetRow() + '0');
 
D

David Wilkinson

chasgl said:
I have a older C++ project from a pre .net Visual studio. I just want it to
run "the old way" in the new environment, not yet wanting to do any dotnet
stuff. Several conversions that worked before are errors now
The code
CString strAsciiLocation = (GetColumn() + 'a' - 1);
strAsciiLocation += (GetRow() + '0');
generates the error

c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\LocationOnBoard.cpp(207): error C2593: 'operator +=' is ambiguous
For the second line GetColumn and GetRow both return integers for example if
both returned 1 I wanted the string a1 for strAsciiLocation.

And
return CString('a' + FromLocation.GetColumn() -1)
+ CString('1' + FromLocation.GetRow() -1)
+ CString('a' + ToLocation.GetColumn() -1)
+ CString('1' + ToLocation.GetRow() -1);
generates four errors of the type
c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\Board.cpp(440): error C2440: 'type cast' : cannot convert from
'int' to 'ATL::CStringT<BaseType,StringTraits>'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
Although the first line of the first example doesn't generate an error.
Any suggestions on how to make these kinds of conversions in the new
environment?

chasgl:

I think you need to cast all these expresssions to char.

But I'm not sure all this concatenation is the most efficient way to
generate these strings. In fact, since the length of these strings is
known up front, I wouldn't use CString at all.

David Wilkinson
 
Top