这是我的打印重载运算符:
ostream& operator<<(ostream& os, const Card& card) {
string str;
if(cardValueCorrect(card._value)){
str += to_string(card._value); ////////////////////////////////////
} else {
str += card._identier;
}
str += suitToChar(card._suit);
return os << str;
}
有人可以帮忙解决这个模棱两可的问题吗,Card_value只是一个普通的int,我不知道那里有什么模棱两可的东西?
Card.cpp: In function âstd::ostream& operator<<(std::ostream&, const Card&)â:
Card.cpp:160: error: call of overloaded âto_string(const int&)â is ambiguous
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:2616: note: candidates are: std::string std::to_string(long double)
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:2610: note: std::string std::to_string(long long unsigned int)
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/basic_string.h:2604: note: std::string std::to_string(long long int)
答案 0 :(得分:0)
1 - 确保包含所有标头:
<string>
<iostream>
2 - 尝试删除using namespace std
行并使用显式标准命名空间规范。
3 - 仅出于测试目的尝试使用显式模板专业化:
std::to_string<int>(card._value);