C++ 成员函数的无效使用(您是否忘记了“()”?)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27712883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ Invalid use Of Member Function (Did You Forget The '()'?)
提问by Steven O'Riordan
I'm having trouble getting my program to compile. The error is happening on line 165-177. All I added was the test for the presence of letters and I got an error, hope you can help! Full Code http://pastebin.com/embed.php?i=WHrSasYk
我在编译我的程序时遇到问题。错误发生在第 165-177 行。我添加的只是字母存在的测试,我得到了一个错误,希望你能帮助!完整代码http://pastebin.com/embed.php?i=WHrSasYk
(Attached below is code)
(下面附上代码)
do
{
cout << "\nCustomer Details:";
cout << "\n\tCustomer Name:";
cout << "\n\t\tFirst Name:";
getline (cin, Cust_FName, '\n');
if (Quotation::Cust_FName.length() <= 1)
ValidCustDetails = false;
else
{
// Error line 165!
for (unsigned short i = 0; i <= Cust_FName.length; i++)
if (!isalpha(Quotation::Cust_FName.at(i)))
ValidCustDetails = false;
}
cin.ignore();
cout << "\t\tLast Name:";
getline (cin, Cust_LName, '\n');
if (Cust_LName.length () <= 1)
ValidCustDetails = false;
else
{
// Error line 177!
for (unsigned short i = 0; i <= Cust_LName.length; i++)
if (!isalpha(Cust_LName.at(i)))
ValidCustDetails = false;
}
cin.ignore();
}
while(!ValidCustDetails);
回答by cdhowie
These lines are your problem:
这些行是你的问题:
for (unsigned short i = 0; i <= Cust_FName.length; i++)
for (unsigned short i = 0; i <= Cust_LName.length; i++)
// ^^
std::string::length
is a function, so you need to invoke it with parens:
std::string::length
是一个函数,所以你需要用括号调用它:
for (unsigned short i = 0; i <= Cust_FName.length(); i++)
for (unsigned short i = 0; i <= Cust_LName.length(); i++)
回答by Jarod42
I suspect that Cust_LName
is a std::string
so you should add ()
after length
:
我怀疑这Cust_LName
是一个std::string
所以你应该在()
后面添加length
:
Cust_LName.length()