【问题标题】:C++ Question,error C2064: term does not evaluate to a function taking 1 argumentsC++ 问题,错误 C2064:术语不计算为采用 1 个参数的函数
【发布时间】:2011-07-08 10:14:33
【问题描述】:

你能帮我用这个简单的C++代码吗,我不知道这里有什么问题?

#include <iostream>
#include <string>
using namespace::std;
template <class Type>
Type binsearch (Type item,Type *table,Type n)
{
    int bot=0;
    int top=n-1;
    int mid, cmp;
    while (bot<= top)
    {
        mid=(bot+top)/2;
        if(item==table(mid))
            return (mid);
        else if (item <table[mid])
            top=mid-1;
        else
            bot=mid+1;
    }
    return -1;
}

int main ()
{

    int nums[]={10, 12, 30, 38, 52, 100};
    cout<< binsearch(52, nums, 6);
}

【问题讨论】:

  • 至少发布错误是什么以及它出现在哪里
  • @NAIEM:我建议您开始学习如何处理错误消息中的信息。编译器可能会告诉您问题出在哪一行,这应该限制了搜索。如果您仍然无法理解该行中发生的情况,请发布问题,但不要忘记提供编译器为您提供的完整信息(即行号)(在报告错误的行中添加注释:@ 987654322@之类的)

标签: c++


【解决方案1】:

table(mid) 应该是 table[mid]

【讨论】:

    【解决方案2】:

    问题是您混淆了[(。而不是

    ---
    mid=(bot+top)/2;
    if(item==table(mid))
        return (mid);
    ---
    

    你需要

    +++
    mid=(bot+top)/2;
    if(item==table[mid])
        return (mid);
    +++
    

    【讨论】:

      【解决方案3】:

      必须是 if(item==table[mid])

      不是

      if(item==table(mid))
      

      【讨论】:

        【解决方案4】:
        if(item==table(mid))
        

        应该是

        if(item==table[mid]) //notice square brackets []
                      ^   ^
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-10-27
          • 2020-02-19
          • 2011-09-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多