转换不明确-C++
Ambiguous conversion - C++
我正试图使用C++和Xcode作为编译器来编写一个函数,以测试a是否为回文。当参数是"C++出生"类型(如int、long、double等)时,代码运行良好,但我希望将函数用于较大的值。所以我使用了BigInteger类型的参数。但是编译器在行上给出了一个错误
BigInteger q = x - floor(x.toLong()/10)*10
表示CCD_ 1。这是整个代码:
#include <iostream>
#include "BigInteger.hh"
using namespace std;
bool isPalindrom(BigInteger x){
long ch = ceil(log10(x.toUnsignedLong())), n[ch];
// cout << floor(log10(x)) + 1 << endl;
for (int i = 0; i <= ch; i++){
BigInteger q = x - floor(x.toLong()/10)*10;
n[i] = q.toInt();
// cout << n[i] << endl;
x /= 10;
}
for (long i = 0; i <= ceil(ch); i++){
if (n[i] != n[ch - i]){
return false;
}
}
return true;
}
我该如何解决这个问题?
如果要一直转换为long,那么使用BigInteger
没有什么意义。
您可以只使用BigInteger
操作来编写该内容,其方式与使用基元整数的方式完全相同:
bool isPalindrome(BigInteger x){
std::vector<int> digits;
while (x > 0)
{
digits.push_back((x % 10).toInt());
x /= 10;
}
size_t sz = digits.size();
for (size_t i = 0; i < sz; i++){
if (digits[i] != digits[sz - i - 1]){
return false;
}
}
return true;
}
也许是
BigInteger q (static_cast<long>(x - floor(x.toLong()/10)*10));
可能会让编译器更高兴。在BigInteger.hh中查找公共构造函数。注意,floor
给出了一个double
,因此子动作也给出了double
,而BigInteger
没有相应的构造函数。
相关文章:
- Visual C++(VS2017)中用户定义的转换不明确
- 重载类方法的不明确调用
- 为函数定义符号不明确的指针参数
- 父类的私有函数会导致对具有相同名称和相似参数的子类中的公共函数的不明确调用
- 在 C++17 中的命名空间和子命名空间中重载运算符是不明确的
- C++ 编译器错误:P1LinkedList.cpp:145:错误:重载的"to_string(int&)"调用不明确
- 对重载函数find_first_not_of的不明确调用
- 不明确的成员模板查找
- gcc出现不明确的模板实例化错误
- 调用'Node'构造函数是不明确的
- 如何解决不明确的运算符过载问题?
- 使用 nullptr 调用重载方法是不明确的
- "fpclassify":对重载函数的不明确调用
- 对"列表"的引用不明确,包括头文件
- 删除全局隐式函数 - 避免使用不明确的运算符
- 当接收到不明确的规范时,表示图的邻接列表的数据结构
- "byte":使用Crypto++和Windows SDK时出现不明确的符号错误
- 使用 std::iterator_traits<> 时编译时错误不明确
- 不明确的函数模板
- Vulkan中的描述符集计数不明确