search

Home  >  Q&A  >  body text

c++ - 为什么会出现 invalid operands 的问题?

代码运行的时候出现了 invalid operands of types 'int (int, int)' and 'int' to binary 'operator<< ' 的错误。
代码如下:

//把M个同样的苹果放在N个同样的盘子里,允许有盘子空着,一共有几种放法?
#include <iostream>

using namespace std;

int count(int m, int n)
{
    if (m <=1 || n <=0) return 1;
    if (m < n)
        return count(m, m);
    else
        return count(m, n-1)+count(m-n, n);
}

void prime()
{
    int apples, plates;
    cin >> apples >> plates;
    count << count(apples, plates);
}

在count<< count(apples, plates),即倒数第二行处提示错误,为什么会出现这种类型的错误呢?

天蓬老师天蓬老师2803 days ago1370

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 14:00:53

    cout << count(apples, plates);

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 14:00:53

    count << count(apples, plates);
    The left side is the function<<The right side is the int type

    Is this possible?

    reply
    0
  • 迷茫

    迷茫2017-04-17 14:00:53

    First tell me the reason why you use it this way

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:00:53

    Sorry, I changed cout to count

    reply
    0
  • Cancelreply