473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Compiling Error in VS C++ .NET that works fine in VS 6.0

I’m very new in C++ programming and am trying to make a decoder tool
just for the purpose of learning. I started my project in VC++ 6.0,
but after a change of PC, I continued my programming in VS .NET.

Now I get a lot of compiling error which I don’t understand. Here is
an extract from the code:

int iOct;
CString sASCII;

sASCII += ((iOct >> 4) + 48);

This works fine in VS 6.0 but gives an error stating it’s “ambiguous”
in .NET!

I do have this workaround :

char cTemp[8];
iOct = ((iOct >> 4) +48);
itoa(iOct,cTemp,16);
sASCII += cTemp;

But it would be nice if the simple VS 6.0 version of the code worked.
Any idea why .NET dislike the original code and if it’s possible to
fix?

BR /// Rob
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 17 '05 #1
6 2710
"bmwrob" <la*********@hotmail-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
But it would be nice if the simple VS 6.0 version of the code worked.
Any idea why .NET dislike the original code and if it’s possible to
fix?


It is often a good idea to post the problematic code AND the full text of of
the error message. That usually rings a bell with someone. Without the text
of the error, someone has to create a project, copy the code and compile.
Some here have the time for that, some don't.

Regards,
Will
Nov 17 '05 #2
Sorry for not being so clear. Here is the complete error message I
get:

c:\MFC\Decoder\DecoderDlg.cpp(592) : error C2593: 'operator +=' is
ambiguous
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\atlmfc\include\cstringt.h(1075): could be
'ATL::CStringT<BaseType,StringTraits>
&ATL::CStringT<BaseType,StringTraits>::operator
+=(wchar_t)'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\atlmfc\include\cstringt.h(1068): or
'ATL::CStringT<BaseType,StringTraits>
&ATL::CStringT<BaseType,StringTraits>::operator +=(unsigned
char)'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\atlmfc\include\cstringt.h(1061): or
'ATL::CStringT<BaseType,StringTraits>
&ATL::CStringT<BaseType,StringTraits>::operator +=(char)'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
while trying to match the argument list '(CString, int)'
BR /// Rob
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 17 '05 #3
On 21 Jun 2004 09:03:08 -0500,
la*********@hotmail-dot-com.no-spam.invalid (bmwrob) wrote:
I’m very new in C++ programming and am trying to make a decoder tool
just for the purpose of learning. I started my project in VC++ 6.0,
but after a change of PC, I continued my programming in VS .NET.

Now I get a lot of compiling error which I don’t understand. Here is
an extract from the code:

int iOct;
CString sASCII;

sASCII += ((iOct >> 4) + 48);

This works fine in VS 6.0 but gives an error stating it’s “ambiguous”
in .NET!

I do have this workaround :

char cTemp[8];
iOct = ((iOct >> 4) +48);
itoa(iOct,cTemp,16);
sASCII += cTemp;

But it would be nice if the simple VS 6.0 version of the code worked.
Are you sure it worked? It may have compiled, but I suspect it didn't
do what you wanted. I suspect it added an ascii character with the
value ((iOct >> 4) +48) to the string, not a string representation of
the number ((iOct >> 4) +48) as you seem to want.
Any idea why .NET dislike the original code and if it’s possible to
fix?


There is no operator += for CString to add an int to a CString.
Instead, it is trying to call one of the 1 or 2 operator+= methods on
CString that take a char argument. I think the reason it used to work
is that you weren't compiling in UNICODE mode, and now you are, which
means that there are two versions of operator+= that can take an int
(one taking char and one wchar_t), hence the ambiguity.

What were you expecting it to do? Add on a string representation of
the integer to the string? In what base? From the workaround code
above you appear to want hex representation. I suggest you just use
the new code (making sure that your cTemp buffer is *definitely* large
enough - 8 might be too small? 64 might be safer...). It looks like
you have found a bug in your code by upgrading!

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Nov 17 '05 #4
The code was part of a function that decodes a BCD number to ASCII.
Yes, the old code worked as I expected. But I did check the new code
and it did not! When I used “itoa” I shouldn’t have added “48”.
In the old code, by shifting my octet 4 bits I can assure that the
value is not greater then 9 as the number was BCD coded. Now by
simply adding 48 I got the number in ASCII format.

I have attached the complete function in the last part of the post.
The input to the function was the actual number of octets I needed to
decode and the file pointer.

I have no idea which mode I was compiling in. How can I check that?

I also tried this out in VS 6.0 for testing, assuming that the octet
never is greater then H’F

ASCII += oct + 48;

This worked in VS 6.0 and simply converted the binary number to
ASCII.

BR /// Rob

CString BCD2ASCII(int num_oct, FILE *fp)
{
int count, iOct, iTemp;
char cTemp[8];
CString sASCII;

for (count=0; count<num_oct; count++)
{

iOct = fgetc(fpHPSDFOA);
iTemp = (iOct & 0xF);

if (iOct == 0xFF); // End of even number found

else if (iTemp == 0xF)
{
iOct = (iOct >> 4) ;
itoa(iOct,cTemp,16);
sASCII += cTemp; // End of odd number found. Store last digit

// old code that doesn’t work in .NET

//sASCII += ((iOct >> 4) + 48); // End of odd number found.
Store last digit
}

else
{
if (iOct <10)
{
sASCII += "0"; // Filler zero for the octet
}

itoa(iOct,cTemp,16);
sASCII += cTemp;
}

}
return sASCII;
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 17 '05 #5
On 28 Jun 2004 09:05:09 -0500,
la*********@hotmail-dot-com.no-spam.invalid (bmwrob) wrote:
The code was part of a function that decodes a BCD number to ASCII.
Yes, the old code worked as I expected. But I did check the new code
and it did not! When I used “itoa” I shouldn’t have added “48”.
In the old code, by shifting my octet 4 bits I can assure that the
value is not greater then 9 as the number was BCD coded. Now by
simply adding 48 I got the number in ASCII format.


If the value *is* an ascii one, you just want:

sASCII += static_cast<char>((iOct >> 4) + 48);

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Nov 17 '05 #6
Thanks Tom. The static cast worked just fine.

BR /// Rob
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: yzzzzz | last post by:
Hi, I am compiling PHP 5.0.2 myself with MySQL support. I did a ./configure --with-mysqli=/usr/local/mysql/bin/mysql_config (see end of post for complete configure) Note: I also have...
4
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
1
by: Mike Hutton | last post by:
I need some help. I am trying to set up our development environment so as to make life easy for my fellow developers (none of whom have used ASP.NET or VS.NET before). We are developing our...
5
by: Nick Gilbert | last post by:
Hi, I'm having problems using Flash Remoting with Web Services for ASP.NET and I've narrowed the problem down to csc.exe when it tries to compile the stub class. Flash Remoting...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
6
by: Josefo | last post by:
Hello all. I am a newbie following the C++ tutorial in : http://www.cplusplus.com/doc/tutorial/templates.html I am unable to succesfully compile any of the examples with templates of this...
8
by: rays | last post by:
Hi, I am trying to port a C++ program which is supposed to be standards compliant. It works fine on Linux with GCC (4.x). But as I try to compile it on Windows, all hell breaks loose. I have been...
0
by: sail777 | last post by:
I am testing the Matlab engdemo.c file shipped with the student version of MatlabR14s3. Unfortunately, Matlab chose *not* to ship the 64 bit .so files with this release. When compiling and linking...
10
by: Tomás Ó hÉilidhe | last post by:
I'd post this on a gcc newsgroup but I'd be more productive talking to the wall. Anyway, let's say someone throws some source code at you for a particular program and says, "Just compile it, it...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.