对重载函数std :: to_string的不确定调用 [英] Ambiguous call to overloaded function - std::to_string

查看:5049
本文介绍了对重载函数std :: to_string的不确定调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试将整数值插入到字符串中时,我认为当我找到std :: to_string时,我的祈祷被回答了,但是当我真正尝试使用它时,由于某种原因,Visual Studio抱怨歧义。这是我的函数的当前化身:

In attempting to insert integer values into a string, I thought that my prayers were answered when I found std::to_string, but for some reason whenever I actually try to use it, Visual Studio complains about ambiguity. Here is the current incarnation of my function:

string get_time_remaining (int elapsed)
{
    string remaining;
    string temp_string;

    int time_remaining = TimeLimit - elapsed;

    int temp_int;

    temp_int = int(time_remaining / 3600);

    if(temp_int == 0)
        remaining = "00 : ";
    else
    {
        temp_string = std::to_string(temp_int);   // Here!
        remaining = temp_string + " : ";
    }

    temp_int = time_remaining % 60 + 1;

    if(temp_int < 10)
        remaining = remaining + "0";

    temp_string = std::to_string(temp_int);

    remaining = remaining + temp_string;

    return remaining;
}



我试过在调用to_string时转换temp_int,我甚至尝试投射应该是整数除法的结果,但无论我做什么,VS吐出这在我:

I have tried casting temp_int inside the call to to_string, and as you can see I even tried casting the result of what should be integer division, but no matter what I do, VS spits this out at me:

d:\my programs\powerplay\powerplay\powerplay.cpp(1285): error C2668: 'std::to_string' : ambiguous call to overloaded function
1>          d:\microsoft visual studio 10.0\vc\include\string(688): could be 'std::string std::to_string(long double)'
1>          d:\microsoft visual studio 10.0\vc\include\string(680): or       'std::string std::to_string(_ULonglong)'
1>          d:\microsoft visual studio 10.0\vc\include\string(672): or       'std::string std::to_string(_Longlong)'

任何帮助将不胜感激。

推荐答案

MSVC11缺少适当的重载 std :: to_string ,所以你必须做 static_cast unsigned long long long long

MSVC11 lacks the proper overloads for std::to_string so you have to do a static_cast to unsigned long long or long long

请注意,此错误已在2012年11月CTP中修复。可以获取此处

Note that this bug is fixed in the November CTP 2012. Which you can get here.

这篇关于对重载函数std :: to_string的不确定调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆