为什么编译器认为传递的是 std::string&而不是 std:string
Why does the compiler think a std::string& is passed not a std:string
我的问题是为什么编译器认为我在processSymbol(const string, enumDataType)
传递一个std::string&。我之前在我的代码中使用了processSymbol(const string, enumDataType)
并按预期工作,但是在这个函数中,我得到了这个错误
error: call of overloaded 'processSymbol(std::string&, symsErrorCode&)' is ambiguous|
note: candidates are:
note: void processSymbol(std::string, symsErrorCode&)|
note: void processSymbol(std::string, symsErrorCode)|
这是我想知道的功能。
void processSearchForSymbols(ifstream & inSyms, BST & symTable){
symsErrorCode symsError;
string symbol;
while(inSyms >> symbol){
symsError = NO_ERROR;
processSymbol(symbol, symsError);
}
}
processSymbol()
编译我认为应该如何的函数是这样的:
void processInsertSymbolData(ifstream & inFile, BST & symTable){
string symbol, value, rFlag, fourCharSymbol;
symsErrorCode symsError;
while(inFile >> symbol >> value >> rFlag){
symsError = NO_ERROR;
processSymbol(symbol, symsError);
if(symsError == NO_ERROR)
{
fourCharSymbol = createFourCharSymbol(symbol);
processValue(value, symsError);
if(symsError == NO_ERROR)
{
processRFlag(rFlag, symsError);
if(symsError == NO_ERROR)
{
insertIntoSymTable(symsError, fourCharSymbol, value, rFlag, symTable);
}
}
}
errorOutput( symsError, symbol, fourCharSymbol, value);
}
return;
}
这是processSymbol(const string symbol, symsErrorCode symsError)
函数
void processSymbol(const string symbol, symsErrorCode symsError){
if(symbol.length() > 10)
{
symsError = LENGTH;
}
else if(!isalpha(symbol[0]))
{
symsError = START_CHAR;
}
else
{
for(unsigned int i = 1; i < symbol.length(); i++)
{
if( !isalnum(symbol[i]) && symbol[i] != '_' )
{
symsError = INVALID_CHAR;
}
}
}
return;
}
编译器无法区分您尝试调用的 processSymbol 的两个声明。 我建议使用指针(*)而不是枚举的&。 这将使编译器清楚地知道您打算调用哪个版本的函数。
processSymbol(const string symbol, symsErrorCode* symsError) ...
相关文章:
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- 使用 std::string () const 函数启动线程或未来
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 如何更改大小(std::string)
- std::string 的对象真的可以移动吗?
- SegFault 同时使用 std::string::operator+= 和函数作为参数
- 无法从 std::string 中提取C++ Unicode 符号
- std::string 构造函数如何处理固定大小的 char[]?
- 真的没有来自 std::string_view 的 std::string 的显式构造函数吗?
- 将C++ std::string 转换为 UTF-16-LE 编码的字符串
- 重载 + 自己的类和 std::string 的运算符
- 如何使用 std::string 作为 QHash 的键?
- 将日语 wstring 转换为 std::string
- 可以从std::string继承以提供类型一致性吗
- 构造函数采用std::string_view与std::string并移动
- 在共享缓冲区内存中创建 ::std::string 对象
- std::string.size() 未知行为
- Valgrind 在 std::string::swap 中报告 SIGILL