473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Ambiguous call

lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;

Error 1 error C2668: 'fabs' : ambiguous call to overloaded function
ezfont.cpp 47 stasm

I first thought that the compiler wants to fight with me because there
where some decimals missing, but it's already .0 and .5.

Also here an error "ambiguous call" is thrown...

lf.lfWidth = (int) (tm.tmAveCharWidth *
fabs (pt.x) / fabs (pt.y) + 0.5) ;
I understand that it's because it's a C function that I have converted
to C++ (at least I think so), but I don't know how to get it right.
Anna.
Oct 21 '08 #1
8 5042
"Anna Smidt" <a.*****@nospamgmail.comschrieb
lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;

Error 1 error C2668: 'fabs' : ambiguous call to overloaded function
ezfont.cpp 47 stasm

I first thought that the compiler wants to fight with me because
there where some decimals missing, but it's already .0 and .5.

Also here an error "ambiguous call" is thrown...

lf.lfWidth = (int) (tm.tmAveCharWidth *
fabs (pt.x) / fabs (pt.y) + 0.5) ;
I understand that it's because it's a C function that I have
converted to C++ (at least I think so), but I don't know how to get
it right. Anna.
See the solution (bottom example) in the documentation on C2668.
http://msdn.microsoft.com/en-us/libr...87(VS.80).aspx

That means, explicitly do the conversion on your own to make it unambiguous
for the compiler:

....(float) fabs (pt.x)...
Is it required to convert the file to C++? You can set the language (C/C++)
and other settings on a per file basis. (however, I don't know what problems
can occur when the linker comes into play...)
Armin

Oct 21 '08 #2
Hi Armin,

I changed

lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;

to

lf.lfHeight = - (int) (float) (fabs (pt.y) / 10.0 + 0.5)
;//MODIFIED BY ANNA:ORIG is without (float)

....and still have that error.

I have only 3 of these errors, so I will change it manually and not set
compiler options on a file-base if I can't help it.

Thanks!
Anna
Oct 21 '08 #3
On Tue, 21 Oct 2008 20:23:42 +0200, Anna Smidt <a.*****@nospamgmail.com>
wrote:
lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;

Error 1 error C2668: 'fabs' : ambiguous call to overloaded function
ezfont.cpp 47 stasm

I first thought that the compiler wants to fight with me because there
where some decimals missing, but it's already .0 and .5.
But you're not passing them to fabs.
>Also here an error "ambiguous call" is thrown...

lf.lfWidth = (int) (tm.tmAveCharWidth *
fabs (pt.x) / fabs (pt.y) + 0.5) ;
I understand that it's because it's a C function that I have converted
to C++ (at least I think so), but I don't know how to get it right.
Anna.
When you get an error like this, copy and paste the entire error message
into your post, because IIRC, the compiler will indicate the overloads
involved in the ambiguity. Also specify the types of pt.x and pt.y. Doing
this will let someone definitively answer your question. I'm going to guess
that pt is a Windows POINT, and thus pt.x and pt.y are LONG, and there are
(at least) fabs(float) and fabs(double) overloads. If this is correct, you
can just cast to double to resolve the ambiguity, e.g.
fabs(static_cast<double>(pt.y)).

--
Doug Harrison
Visual C++ MVP
Oct 21 '08 #4
"Anna Smidt" <a.*****@nospamgmail.comschrieb
Hi Armin,

I changed

lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;

to

lf.lfHeight = - (int) (float) (fabs (pt.y) / 10.0 + 0.5)
;//MODIFIED BY ANNA:ORIG is without (float)

...and still have that error.

I have only 3 of these errors, so I will change it manually and not
set compiler options on a file-base if I can't help it.

Thanks!
Anna
Sorry, my fault. But obviously you didn't understand the meaning of the
error message. ;-) pt.y is an integer, I guess, and none of the overloads
accepts an integer. Therefore, pt.y must be converted:

....fabs((float) pt.y)...
Armin

Oct 21 '08 #5
On Tue, 21 Oct 2008 22:44:17 +0200, "Armin Zingler" <az*******@freenet.de>
wrote:
>Sorry, my fault. But obviously you didn't understand the meaning of the
error message. ;-) pt.y is an integer, I guess, and none of the overloads
accepts an integer. Therefore, pt.y must be converted:

...fabs((float) pt.y)...
Casting a 32 bit integer to a 32 bit float may lose precision and may even
throw a structured exception (I don't recall if this is masked by default
or not). Basically, the only reason to ever use float is to save space, and
casting to double is the right choice here.

--
Doug Harrison
Visual C++ MVP
Oct 21 '08 #6
"Doug Harrison [MVP]" <ds*@mvps.orgschrieb

...fabs((float) pt.y)...

Casting a 32 bit integer to a 32 bit float may lose precision and
may even throw a structured exception (I don't recall if this is
masked by default or not). Basically, the only reason to ever use
float is to save space, and casting to double is the right choice
here.
Just wanted to show "how to", and as the final result is int anyway, it
shouldn't matter much. But in general you're right.
Maybe I'm sometimes still on the float = 4 bytes = native = fastest trip,
which is outdated, of course. ;-)
Armin

Oct 21 '08 #7
Doug Harrison [MVP] wrote:
On Tue, 21 Oct 2008 20:23:42 +0200, Anna Smidt
<a.*****@nospamgmail.comwrote:
> lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ;

Error 1 error C2668: 'fabs' : ambiguous call to overloaded function
ezfont.cpp 47 stasm

I first thought that the compiler wants to fight with me because
there where some decimals missing, but it's already .0 and .5.

But you're not passing them to fabs.
No, so why use fabs in the first place? :-)

In C++ you can just use std::abs and the compiler will select the
proper overload for you.

On the other hand, why convert to float just to get a rounded divide
by 10?

Using (abs(pt.y) + 5) / 10 will do just as well.
Bo Persson

Oct 21 '08 #8
On Wed, 22 Oct 2008 00:26:14 +0200, "Bo Persson" <bo*@gmb.dkwrote:
>No, so why use fabs in the first place? :-)
Now that's a good point. :)
>In C++ you can just use std::abs and the compiler will select the
proper overload for you.

On the other hand, why convert to float just to get a rounded divide
by 10?

Using (abs(pt.y) + 5) / 10 will do just as well.
That's susceptible to overflow in the addition, but in this context,
calculating a font height, I agree with you.

--
Doug Harrison
Visual C++ MVP
Oct 22 '08 #9

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

Similar topics

7
by: ishekara | last post by:
Hi, I am having a class template which is used to convert from one type another. I am having a problem when i use the copy constructor with same type. code. #include "stdio.h" template...
5
by: rolandz | last post by:
Hi, Maybe somebody has been fighting with the problem that I do, currently. I have a class that has method f(). The two versions of the f() method accept different objects: Int and Short. These...
6
by: c1t1z3n | last post by:
hiya, i'm having this weird error on my project. As far as I know "ambiguous call to overloaded function" should only occur when the compiler must choose from several methods, but here i don't think...
1
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; void print(char c) { cout << "from print(char c) : " << c << endl; return;
9
Ganon11
by: Ganon11 | last post by:
I was working on a program this morning that required me to use the pow function (to compute 2^i at one point, and 3^i at another). I used the following code: std::vector<int>...
4
by: Joseph Turian | last post by:
I have a templated class with the following methods: Vocab(const T& t); Vocab(unsigned uid); However, when T = unsigned, and I call Vocab(unsigned(0)) then the compiler rightly complains about...
3
by: valoh | last post by:
Hi, is this legal c++ code? template <typename BaseTstruct A { BaseT& this_() { return *static_cast<BaseT*>(this); } template <typename Tvoid Foo() { this_().Bar<T>(); } template...
1
by: Ruki | last post by:
I want to overload function to swap two others types, for example, type<T>, T* and so on, but I can't compile the following code at VC 6.0. The compiler says : error C2667: 'swap' : none of 2...
32
by: Anna Smidt | last post by:
I am having an "ambiguous call to overloaded function" error again. This is the function: int nGetProfWidth (int ncols, unsigned ProfSpec) { if ((ProfSpec & PROF_2d) == 0) return ncols;...
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
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
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...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.