473,770 Members | 7,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2733
"bmwrob" <la*********@ho tmail-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\cstrin gt.h(1075): could be
'ATL::CStringT< BaseType,String Traits>
&ATL::CStringT< BaseType,String Traits>::operat or
+=(wchar_t)'
with
[
BaseType=char,
StringTraits=St rTraitMFC_DLL<c har>
]
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\atlmfc \include\cstrin gt.h(1068): or
'ATL::CStringT< BaseType,String Traits>
&ATL::CStringT< BaseType,String Traits>::operat or +=(unsigned
char)'
with
[
BaseType=char,
StringTraits=St rTraitMFC_DLL<c har>
]
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\atlmfc \include\cstrin gt.h(1061): or
'ATL::CStringT< BaseType,String Traits>
&ATL::CStringT< BaseType,String Traits>::operat or +=(char)'
with
[
BaseType=char,
StringTraits=St rTraitMFC_DLL<c har>
]
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*********@hot mail-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,cTem p,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*********@hot mail-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<cha r>((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
1893
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 --with-mysql=/usr/local/mysql/. However, I get the same errors when I configure without the mysql extension, just mysqli. And as the documentation says, I use the same version of MySQL for both extensions to avoid conflicts.
4
11363
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 LNK2020: unresolved token (0A000007) memset LINK : error LNK2020: unresolved token (0A000008) free LINK : error LNK2020: unresolved token (0A00000A) atexit LINK : error LNK2020: unresolved token (0A000028) wcscpy LINK : error LNK2020: unresolved...
1
1731
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 intranet which will comprise basic content with a number of small data-driven ASP.NET applications. I need to keep things simple, so I need to avoid stuff which needs too much in-depth knowledge to work.
5
2048
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 (flashgateway.dll) is calling the following command line to compile the stub class: "csc.exe" /out:ExampleWebService.dll /t:library ExampleWebService.cs
0
9747
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. I need it to be compiled with threads. Anyone have any wisdom on how best to do this? Here's a transcript of my latest attempt. It's long; you might want to skip to the bottom, where I try "make" and the fatal errors start happening.
6
2598
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 tutorial. I use the standard c++ compiler which comes with ubuntu breezy distro. I guess that somethig is wrong with it or (more likely..) I should use some option when compiling. This is, for instance, one of the codes: // template specialization...
8
2298
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 struggling with several free (as beer) compilers on windows, but none of them does the job. I am not sure how much of the blame goes to our code and how much to the compilers. By the way the platform is Windows XP and all the softwares mentioned...
0
1057
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 on 32bit linux everything works fine! Engine starts and demo works great. I next reboot into 64b mode and when I run, I get an error that the matlab engine did not start. I also recompile under 64 bit linux using -m32 flags and everything...
10
2210
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 works fine". Now admittedly, I tend to have a phobia of this situation because I recall from my Windows days the numerous times I was given code that was supposedly "good to go", but which failed to compile for some stupid reason. Of course I...
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10004
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.