mutual recursion

Discussion in 'C++' started by Dan, Sep 20, 2010.

  1. Dan

    Dan Guest

    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++?
     
    Dan, Sep 20, 2010
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Sep 20, 2010
    #2
    1. Advertising

  3. 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
     
    Victor Bazarov, Sep 20, 2010
    #3
  4. 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++?


    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) { ... }
     
    Juha Nieminen, Sep 21, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vjeran Marcinko

    Mutual EJB possible?

    Vjeran Marcinko, Oct 17, 2003, in forum: Java
    Replies:
    3
    Views:
    453
    Michael Borgwardt
    Oct 17, 2003
  2. Giambattista Bloisi

    non-blocking mutual exclusion

    Giambattista Bloisi, Dec 16, 2003, in forum: Java
    Replies:
    1
    Views:
    413
    Matt Humphrey
    Dec 16, 2003
  3. Dan

    mutual recursion

    Dan, Sep 20, 2010, in forum: C++
    Replies:
    1
    Views:
    286
    Victor Bazarov
    Sep 20, 2010
  4. Replies:
    8
    Views:
    745
    John Reye
    Apr 26, 2012
  5. Peter Brooks

    Solving the problem of mutual recursion

    Peter Brooks, May 26, 2013, in forum: Python
    Replies:
    14
    Views:
    140
    Chris Angelico
    May 27, 2013
Loading...

Share This Page