English 中文(简体)
fabs : 使用模板时对超载功能的模糊调用
原标题: fabs : ambiguous call to overloaded function when using templates
  • 时间:2012-05-24 20:00:47
  •  标签:
  • c++

我的职能如下:

T* tContainer_t<T, R>::Remove( T item )
{    
    typename R::const_iterator it = std::find_if(Container.begin(), Container.end(),  [item](const T* v) { return std::fabs(*v - item) < DBL_EPSILON; });
    if (it != Container.end())
    {
        ...
    }
    else
        return NULL;
}

T 可以是 int , twoth , float 等。

编译器给了我 fabs : 当使用模板 时, 模糊调用到超载功能

问题是什么? 如何解决?

谢谢

最佳回答

T 可以是 int 、双倍、 float 等。

std > 有三个超载: C++中的 float two load loud muble

如果您试图调用 std::fabs 并使用类型 int 的参数来调用 int , 则会因超载模糊性而发生汇编错误。 int 的参数与所有三种可用的超载相同。

您可以将参数投向已知的类型(例如 double long mular double ),这样可以消除模糊性,也可以将调用 fabs 的调用包在对整数类型参数进行模糊的模板中。

换句话说,C++有 std::abs ,它以整数和浮点类型超载(以 中声明)。此外,如果您最近有一个执行C+171的标准图书馆实施程序,则用整数类型参数呼叫std::fabs 将自动将参数转换为类型 twork ,因此没有模糊性。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?