我在C ++中有一个非常基本的问题。我在if条件中调用login()函数,并在编译时给出错误。
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
void login();
int main() {
string login;
int passcode;
cout << "login ";
cin >> login;
cout << "passcode ";
cin >> passcode;
if(login == "admin" && passcode == 123) {
login();
}
else {
cout << "It's not the Correct Passcode ";
}
return 0;
system("pause");
} // main()
void login() {
cout << "You've successfully Logged into the Software ";
return ;
}
答案 0 :(得分:4)
你有一个名字冲突。
login()
是一个函数名称。
但login
也是std::string
的实例。
由于类可能重载 ()
运算符,编译器会将此标记为潜在的歧义并发出错误。
(请注意,伪装成函数的对象实例称为函数对象 - 并且确实非常有用,特别是在C ++ 11之前。)