c++成员函数的无效使用(您忘记'()'了吗?)

时间:2020-12-02 09:44:14

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);

2 个解决方案

#1


8  

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:

string::length是函数,所以需要使用parens:

for (unsigned short i = 0; i <= Cust_FName.length(); i++)
for (unsigned short i = 0; i <= Cust_LName.length(); i++)

#2


2  

I suspect that Cust_LName is a std::string so you should add () after length :

我怀疑Cust_LName是std::string,所以你应该在长度后添加():

Cust_LName.length()

#1


8  

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:

string::length是函数,所以需要使用parens:

for (unsigned short i = 0; i <= Cust_FName.length(); i++)
for (unsigned short i = 0; i <= Cust_LName.length(); i++)

#2


2  

I suspect that Cust_LName is a std::string so you should add () after length :

我怀疑Cust_LName是std::string,所以你应该在长度后添加():

Cust_LName.length()