"Cannot overload functions by return type alone"错误
"Cannot overload functions by return type alone" error
当涉及到我的函数时,我一直得到"不能重载仅由返回类型区分的函数"字符串进程打开(字符名称)我不知道为什么。我已经将程序削减为基本的外壳,但仍然没有运气。任何帮助将不胜感激。
编译过程中的实际视觉工作室错误显示"缺少类型说明符 - 假设为 int。注意:C++不支持默认整数。
#include <iostream>
#include <string>
#include <fstream>
char openCommand();
string processOpen(char entryReturn);
bool logIn(string name);
bool addNewMember(string name);
void processQuit();
//Global Variables
string memberlist = "memberlist.txt";
string checkedOutList = "checkedoutbooks.txt";
using namespace std;
int main() {
char entryReturn = ' ';
string name;
while (entryReturn != 'q') {
entryReturn = openCommand();
name = processOpen(entryReturn);
}
return 0;
}
该函数看起来像
string processOpen(char entryReturn) {
bool allReadyThere = false;
string name = " ";
//This will process the <log in> selection
if (entryReturn == 'a')
{
cout << "Enter your first and last name" << endl;
cin.ignore();
getline(cin, name);
allReadyThere = logIn(name);
if (allReadyThere == false)
{
cout << "You need to register
as you don't have an account" << endl;
}
}
//This will process the <register> selection
else if (entryReturn == 'b')
{
cout << "Enter your first and last name" << endl;
cin.ignore();
getline(cin, name);
allReadyThere = addNewMember(name);
if (allReadyThere == true) {
cout << "you already have an account" << endl;
}
}
else if (entryReturn == 'q') {
processQuit();
}
else
{
cout << "This is a non working command";
}
return name;
}
善待代码 我还是有点新。提前谢谢。
在行:
string processOpen(char entryReturn);
编译器不知道string
是什么意思。你应该在这里写std::string
。
显然,您的编译器猜到您拼写错误int
.(现在编译器很聪明,对吧?
然后,后来你写了using namespace std;
,然后是string processOpen(char entryReturn) {
.此时,编译器在 namespace std
中找到 string
,它看到您定义了两个具有相同名称和参数的函数,但一个返回 int
和一个返回 std::string
,这是不允许的。
这是一个很好的例子,说明为什么您应该将注意力集中在编译器的第一个输出消息上(无论是"错误"还是"警告",实际上都没有区别)。 遇到错误后,编译器会猜测您的意思并尝试继续编译,但显然任何后续消息都会受到此猜测结果的影响,如果它猜对了。
修复第一条消息后,重新编译以查看其他"级联"消息是否也消失。
相关文章:
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 在 QVector<std::unique_ptr 上使用 std::find<Type>>
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 使用 cmake 的 Linux 终端上的"Conversion to non-scalar type is requested"错误
- 控制到达非空函数clang(-Wreturn-type)的末尾
- std::unordered_map 类型对象声明期间出现"field has incomplete type"错误
- 将系数存储在头文件的数组中("does not name a type"错误)
- 尝试打开 ifstream 时出现"Incomplete type"错误
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 在"结构提升::enable_if<提升::is_pod<T>,无效>"中没有名为"type"的类型
- "Missing type specifier - int assumed"无法通过向主函数添加"return 0"来解决
- OpenCV CV_16F type
- C++ "错误:在'类 std::result_of< ... >"中没有名为'type'的类型"
- 将内存分配返回值强制转换为 TYPE 数组
- C++ 一个lambda浅拷贝const Type&如果它被赋予一个命名捕获,如[copy=val](){}?
- reference_wrapper导致"incomplete type is not allowed"
- 继承类时"invalid use of incomplete type ‘class tree_node_t’"
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- "Cannot overload functions distinguished by return type alone"是什么意思?
- "Cannot overload functions by return type alone"错误