c++ - 为什么我会收到此错误?错误:类型为 'int'和 'int(int, int)'的无效操作数为二进制 'operator/'

标签 c++

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int n1, n2;
    cin >> n1 >> n2;
    int lcm =  n1 * n2; //Line 2
    int rem = lcm / gcd;
    cout << gcd(n1, n2) << endl;
    cout << rem << endl;
我在第2行收到一条错误消息,说“错误:二进制'operator /'的类型为'int'和'int(int,int)'的无效操作数”。我使用Sublime Text Editor进行编译。

最佳答案

由于无法将整数除以函数,因此出现错误。
代替

    int rem = lcm / gcd;
看来您想调用gcd函数。
    int rem = lcm / gcd(n1, n2);

关于c++ - 为什么我会收到此错误?错误:类型为 'int'和 'int(int, int)'的无效操作数为二进制 'operator/',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64401269/

相关文章:

c++ - 确保 QSerialPort.close 在程序执行完成之前完成?

c++ - C++ 中 TCP 套接字的 recv 函数

c++ - 使用const char *键映射C++检索null

c++ - 如何将数组保存到两个类方法中?

c++ - 我如何手动调用 SEL_MenuHandler

c++ - 使用正确数量的逻辑处理器

c++ - 使用接受 char 指针的函数调用 pthread_create

c++ - 使用 waf 构建系统将程序与 Boost.Asio 链接

c++ - 当 lib 文件夹中同时存在静态和共享 C++ 库时,仅链接静态库

c++ - C - 枚举索引数组的优点/缺点