to_string( const /& n) 是 ambiguos
to_string( const /& n) is ambiguos
我正在开发一个带有二进制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
。
相关文章:
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- std中有类似find_last_of的函数,而string中没有
- 使用 std::string () const 函数启动线程或未来
- 使用char类型将decimal转换为string,将string转换为decimal
- 迭代和比较映射<字符串、矢量<string>> c++ 中的值
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 将向量解析<string>为字符串
- 'string.assign(string.data(), 5)' 是明确定义的还是 UB?
- 如何更改大小(std::string)
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- C++:如何将 unix 时间的字符串转换为 *tm?(使用时间错误:"cannot convert 'String' to 'tm*' ")
- std::string 的对象真的可以移动吗?
- 与'operator='不匹配(操作数类型'String'且"void")
- SegFault 同时使用 std::string::operator+= 和函数作为参数
- 无法从 std::string 中提取C++ Unicode 符号
- std::string 构造函数如何处理固定大小的 char[]?
- <string> 使用 for 循环写入向量
- 确切地说,如何解释 std::getline(stream, string) 函数在C++中填充的字符串