This question may sound silly. But I am trying to create a function inside a function. But I am getting:
error : a function-definition is not allowed here before ‘{’ token
Can someone please explain me ? how to solve this.
#include <iostream>
using namespace std;
class abc{
public:
int func1(int key){
int i=0;
void func2(){
i++;
i++;
cout<<i;
}
func2();
return 0;
}
};
int main()
{
abc *obj= new abc();
obj->func1(5);
return 0;
}
and then I want to implement recursion in func1
, like:
int func1(int key){
int func2(){
//code
}
//code
func1(func2);
}
Can I do this in C++?