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

标签 c++ compiler-errors containers members

我在编译我的程序时遇到了问题。错误发生在第 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);

最佳答案

这些行是你的问题:

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

关于C++ 成员函数的无效使用(你忘记了 '()' 了吗?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27712883/

相关文章:

linux - Docker——几个容器

c++ - 刷新 QGraphicsScene/QGraphicsView

c++ - OpenCV 3.2 for python with CUDA in Windows

c++ - cout 变量和通过引用更改变量的函数

c++ - g++-6 阴影模板参数错误,而 g++-5 没有

c++ - 适用于 Dymola 的 Microsoft Visual C++ 编译器

java - 我在 java 9 中发现了编译器错误吗?

linux - 指定 -t 和 -i 对 docker run 来说不是多余的吗?

c++ - 如何解决编译器警告 'implicit declaration of function memset'

c++ - 在 vector 中存储基于 CRTP 的类时遇到问题