Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > mutual recursion

Reply
Thread Tools

mutual recursion

 
 
Dan
Guest
Posts: n/a
 
      09-20-2010
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++?
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-20-2010
On 9/20/2010 1:54 PM, Dan wrote:
> 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
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-20-2010
On 9/20/2010 1:54 PM, Dan wrote:
> 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
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      09-21-2010
Dan <(E-Mail Removed)> wrote:
> 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) { ... }
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
va_arg... recursion: changing arguments and the using recursion jononanon@googlemail.com C Programming 8 04-26-2012 08:37 PM
mutual recursion Dan C++ 1 09-20-2010 06:13 PM
ISIS and EIGRP mutual redistribution --Help! phillip Cisco 2 09-19-2008 08:27 PM
Problems mutual redistributing of ISIS and EIGRP phillip Cisco 5 12-07-2004 07:49 PM
Mutual EJB possible? Vjeran Marcinko Java 3 10-17-2003 09:21 PM



Advertisments