C++调用对象 'int'不是函数也不是函数指针

标签 c++ recursion

<分区>

我是 C++ 的新手,我正在创建一个程序来使用递归计算数字的幂。写完所有代码后,出现错误:

被调用对象“int”不是函数或函数指针。

这是我的完整代码:

#include <iostream>
using namespace std;


int power(int, int);
int main(){

cout << "enter a number " << endl; 

int no, power;

cin >> no;

cout << "enter a power" << endl; 

cin >> power;

cout << "answer is " << power(no, power) << endl; 



return 0;

}

int power(int number,int pow){
if (pow == 1){

return number;
}else {


return number* power(number, pow - 1);

}


}

由于我是新手,所以我不知道这意味着什么。 提前致谢

最佳答案

您首先将 power 声明为整数:

int no, power;

然后尝试将其作为函数调用:

power(no, power)

他们不能同名。重命名您的整数或函数。

关于C++调用对象 'int'不是函数也不是函数指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33452178/

相关文章:

javascript - 替换以下划线开头的名称

java 递归链表

c++ - Boost.spirit (x3, boost 1.64) : how to implement this recursive rule correctly, 这可能吗?

ruby - 高效的置换树算法

c++ - 特殊情况不返回的递归返回函数

c++ - 使用未知指针类型调用函数重载

C++11 对象指针列表的初始化

c++ - 尽管没有 #include,Visual Studio C++ 源文件仍可访问?

c++ - 有什么需要,局部静态变量在编译时分配内存?

c++ - 如何使用nlohmann检查c++中嵌套json中是否存在 key