【问题标题】:C++ Invalid use Of Member Function (Did You Forget The '()'?)C++ 成员函数的无效使用(你忘记了'()'吗?)
【发布时间】:2014-12-30 21:32:35
【问题描述】:

我无法编译我的程序。错误发生在第 165-177 行。我添加的只是测试字母是否存在,我得到了一个错误,希望你能帮忙! 完整代码http://pastebin.com/embed.php?i=WHrSasYk

(下面附上代码)

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

【问题讨论】:

    标签: c++ compiler-errors containers members


    【解决方案1】:

    这些是你的问题:

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

    std::string::length 是一个函数,所以你需要用括号调用它:

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

    【讨论】:

    • 要修复运行时错误,请将&lt;= 替换为&lt;!=
    【解决方案2】:

    我怀疑Cust_LNamestd::string 所以你应该在length 之后添加()

    Cust_LName.length()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      相关资源
      最近更新 更多