to_string( const /& n) 是 ambiguos

to_string( const /& n) is ambiguos

本文关键字:ambiguos string const to      更新时间:2023-10-16

我正在开发一个带有二进制cpp-api的软件。

现在我遇到了一个问题,在我安装的raspian和代码块上,我无法使用提供的预编译.so库来处理binacpp头。

所以我读到我需要为我的系统编译它,并试图通过终端运行make,现在发生了这种情况:

pi@raspberrypi:~/Desktop/patch/src $ make
g++ -I../lib/libcurl-7.56.0/include -I../lib/jsoncpp-1.8.3/include -c binacpp.cpp  -fPIC   -o ../lib/libbinacpp/lib/binacpp.o 
binacpp.cpp: In static member function ‘static void BinaCPP::send_order(const char*, const char*, const char*, const char*, double, double, const char*, double, double, long int, Json::Value&)’:
binacpp.cpp:909:39: error: call of overloaded ‘to_string(double&)’ is ambiguous
post_data.append( to_string( quantity) );
^
In file included from binacpp.cpp:16:0:
binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>]
inline string to_string (const T& t)
^~~~~~~~~
binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double)
static std::string to_string(double val)
^~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
from /usr/include/c++/6/bits/locale_classes.h:40,
from /usr/include/c++/6/bits/ios_base.h:41,
from /usr/include/c++/6/ios:42,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from binacpp.h:19,
from binacpp.cpp:14:
/usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double)
to_string(long double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double)
to_string(double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float)
to_string(float __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int)
to_string(unsigned long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int)
to_string(long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int)
to_string(unsigned long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int)
to_string(long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int)
to_string(unsigned __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int)
to_string(int __val)
^~~~~~~~~
binacpp.cpp:912:36: error: call of overloaded ‘to_string(double&)’ is ambiguous
post_data.append( to_string( price) );
^
In file included from binacpp.cpp:16:0:
binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>]
inline string to_string (const T& t)
^~~~~~~~~
binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double)
static std::string to_string(double val)
^~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
from /usr/include/c++/6/bits/locale_classes.h:40,
from /usr/include/c++/6/bits/ios_base.h:41,
from /usr/include/c++/6/ios:42,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from binacpp.h:19,
from binacpp.cpp:14:
/usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double)
to_string(long double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double)
to_string(double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float)
to_string(float __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int)
to_string(unsigned long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int)
to_string(long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int)
to_string(unsigned long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int)
to_string(long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int)
to_string(unsigned __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int)
to_string(int __val)
^~~~~~~~~
binacpp.cpp:921:42: error: call of overloaded ‘to_string(double&)’ is ambiguous
post_data.append( to_string( stopPrice ) );
^
In file included from binacpp.cpp:16:0:
binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>]
inline string to_string (const T& t)
^~~~~~~~~
binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double)
static std::string to_string(double val)
^~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
from /usr/include/c++/6/bits/locale_classes.h:40,
from /usr/include/c++/6/bits/ios_base.h:41,
from /usr/include/c++/6/ios:42,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from binacpp.h:19,
from binacpp.cpp:14:
/usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double)
to_string(long double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double)
to_string(double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float)
to_string(float __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int)
to_string(unsigned long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int)
to_string(long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int)
to_string(unsigned long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int)
to_string(long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int)
to_string(unsigned __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int)
to_string(int __val)
^~~~~~~~~
binacpp.cpp:926:43: error: call of overloaded ‘to_string(double&)’ is ambiguous
post_data.append( to_string( icebergQty ) );
^
In file included from binacpp.cpp:16:0:
binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>]
inline string to_string (const T& t)
^~~~~~~~~
binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double)
static std::string to_string(double val)
^~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
from /usr/include/c++/6/bits/locale_classes.h:40,
from /usr/include/c++/6/bits/ios_base.h:41,
from /usr/include/c++/6/ios:42,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from binacpp.h:19,
from binacpp.cpp:14:
/usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double)
to_string(long double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double)
to_string(double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float)
to_string(float __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int)
to_string(unsigned long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int)
to_string(long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int)
to_string(unsigned long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int)
to_string(long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int)
to_string(unsigned __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int)
to_string(int __val)
^~~~~~~~~
binacpp.cpp: In static member function ‘static void BinaCPP::withdraw(const char*, const char*, const char*, double, const char*, long int, Json::Value&)’:
binacpp.cpp:1384:38: error: call of overloaded ‘to_string(double&)’ is ambiguous
post_data.append( to_string( amount ));
^
In file included from binacpp.cpp:16:0:
binacpp_utils.h:28:15: note: candidate: std::__cxx11::string to_string(const T&) [with T = double; std::__cxx11::string = std::__cxx11::basic_string<char>]
inline string to_string (const T& t)
^~~~~~~~~
binacpp_utils.h:36:20: note: candidate: std::__cxx11::string to_string(double)
static std::string to_string(double val)
^~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
from /usr/include/c++/6/bits/locale_classes.h:40,
from /usr/include/c++/6/bits/ios_base.h:41,
from /usr/include/c++/6/ios:42,
from /usr/include/c++/6/ostream:38,
from /usr/include/c++/6/iostream:39,
from binacpp.h:19,
from binacpp.cpp:14:
/usr/include/c++/6/bits/basic_string.h:5522:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long double)
to_string(long double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5513:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(double)
to_string(double __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5504:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(float)
to_string(float __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5498:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long unsigned int)
to_string(unsigned long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5492:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long long int)
to_string(long long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5486:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long unsigned int)
to_string(unsigned long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5481:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(long int)
to_string(long __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5475:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(unsigned int)
to_string(unsigned __val)
^~~~~~~~~
/usr/include/c++/6/bits/basic_string.h:5470:3: note: candidate: std::__cxx11::string std::__cxx11::to_string(int)
to_string(int __val)
^~~~~~~~~
Makefile:38: recipe for target '../lib/libbinacpp/lib/binacpp.o' failed
make: *** [../lib/libbinacpp/lib/binacpp.o] Error 1

现在错误列表更长了,但我试图捕捉终端错误的第一部分和最后一部分。

我试着用以下代码修补它:

#include <string>   
#include <sstream>
namespace patch
{ 
template < typename T > std::string to_string( const T& n )
{   
std::ostringstream stm ;
stm<<n ;
return stm.str() ;
}
}

我在另一个问题中读到,这将解决更换每个时的问题

to_string()

带有

patch::to_string()

我试过了,结果完全一样(实际上屏幕截图是编辑后的)

我想要使用的API可以在这里下载:https://github.com/binance-exchange/binacpp

就像我说的,我用的是树莓派和rasbian。

以及码块。

提前感谢AD

正如错误消息所说,问题在于调用不明确。不会,除非binacpp_utils.h文件在全局范围中包含自己的to_string模板,有一个using namespace std语句。这些都是严重的错误,破坏了C++11工具链的构建。

您应该向库的开发人员提出问题。

同时,全局名称空间被破坏了,但您仍然可以在自己的代码中显式引用std::to_string