mutual recursion

D

Dan

I have a program where I really need something like this :

int horizontal(int a , int b){

.....
vertical (c ,d);
......
}

int vertical (int a , int b ){
.........
horizontal(c,d)
.........
}

It won't compile , and restructuring would greatly obfuscate the
code . What's the easiest solution to do something like this in C++?
 
V

Victor Bazarov

I have a program where I really need something like this :

int horizontal(int a , int b){

....
vertical (c ,d);
.....
}

int vertical (int a , int b ){
........
horizontal(c,d)
........
}

It won't compile ,

Why do you think that?
> and restructuring would greatly obfuscate the
code . What's the easiest solution to do something like this in C++?

Add the declaration of 'vertical' and place it above the function you
call it in:

int vertical(int,int);

int horizontal(int a, int b) ...

V
 
V

Victor Bazarov

I have a program where I really need something like this :

int horizontal(int a , int b){

....
vertical (c ,d);
.....
}

int vertical (int a , int b ){
........
horizontal(c,d)
........
}

It won't compile , and restructuring would greatly obfuscate the
code . What's the easiest solution to do something like this in C++?

And next time please read the FAQ 5.2.

V
 
J

Juha Nieminen

Dan said:
I have a program where I really need something like this :

int horizontal(int a , int b){

....
vertical (c ,d);
.....
}

int vertical (int a , int b ){
........
horizontal(c,d)
........
}

It won't compile , and restructuring would greatly obfuscate the
code . What's the easiest solution to do something like this in C++?

You have to declare a function before calling it. Hence declare it:

int vertical(int a, int b);

int horizontal(int a, int b) { ... }
int vertical(int a, int b) { ... }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top