C++ &引用;不能仅按返回类型重载函数”;错误
当涉及到我的函数时,我总是得到一个“不能仅通过返回类型来区分重载函数” 字符串处理打开(字符名称) 我不知道为什么。我已经把程序简化为基本的shell,但仍然没有运气。任何帮助都将不胜感激 编译期间的实际visual studio错误为 “缺失类型说明符-int假设。注释:C++不支持Debug T-INT/<C++ &引用;不能仅按返回类型重载函数”;错误,c++,C++,当涉及到我的函数时,我总是得到一个“不能仅通过返回类型来区分重载函数” 字符串处理打开(字符名称) 我不知道为什么。我已经把程序简化为基本的shell,但仍然没有运气。任何帮助都将不胜感激 编译期间的实际visual studio错误为 “缺失类型说明符-int假设。注释:C++不支持Debug T-INT/< #include <iostream> #include <string> #include <fstream> char openCommand
#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;
}
#包括
#包括
#包括
char openCommand();
字符串processOpen(charentryreturn);
bool登录(字符串名称);
bool addNewMember(字符串名称);
void processQuit();
//全局变量
字符串memberlist=“memberlist.txt”;
字符串checkedOutList=“checkedoutbooks.txt”;
使用名称空间std;
int main(){
char entryReturn='';
字符串名;
while(entryReturn!=“q”){
entryReturn=openCommand();
name=processOpen(entryReturn);
}
返回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){
bool allReadyThere=false;
字符串名称=”;
//这将处理选择
if(entryReturn='a')
{
cout在直线上:
string processOpen(char entryReturn);
编译器不知道string
是什么意思。您应该在这里编写std::string
显然,你的编译器猜测你错发了int
(现在的编译器很聪明,对吧?)
然后,稍后您使用namespace std;
编写了,后跟字符串processOpen(char entryReturn){
。此时,编译器在命名空间std
中找到string
,它看到您定义了两个具有相同名称和参数的函数,但一个返回int
,另一个返回std::string
,这是不允许的
这是一个很好的例子,说明了为什么您应该将注意力集中在编译器的第一条输出消息上(无论是“错误”还是“警告”,实际上都没有区别)。遇到错误后,编译器会猜测您的意思,并尝试继续编译,但很明显,如果猜测不正确,任何后续消息都会受到此猜测结果的影响
修复第一条消息后,重新编译以查看其他“级联”消息是否也消失。请正确设置代码格式(缩进,删除所有多余的垂直空白,修复断开的字符串),然后发布准确的错误消息。好的,请给我第二行。对不起,请给我们指出编译器给出的错误行。@Paul您在哪一行得到错误?第二个函数声明(此屏幕上的第7行???)。它是字符串processOpen(char entryReturn)。