Help in combining two functions in c++

前端 未结 4 2017
野性不改
野性不改 2021-01-29 13:00

I am just trying something with somebody else\'s code.

I have two functions:

int Triangle(Render *render, int numParts, Token *nameList, Pointer *valueLi         


        
4条回答
  •  粉色の甜心
    2021-01-29 13:35

    You shouldn't put functions together, you should split them apart. Put a new function wherever you can name them -- try to make them as small as you can. If you want a function that does all of that stuff, have a function that calls the other functions.

    int foobar() {
    
        int a;
        int b;
    
        /* do a whole bunch of stuff with a */
    
        /* do a whole bunch of stuff with b */
    
        return  a + b;
    
    }
    

    this is sort of what you're trying to do. Instead, do this:

    int foo(){
    
        int a;
    
        /* do a bunch of stuff with a */
    
        return a;
    
    }
    
    int bar() {
    
        int b;
    
        /* do a bunch of stuff with b */
    
        return b;
    
    }
    
    int foobar() {
    
        return foo() + bar();
    
    }
    

    The result will be cleaner, easier to maintain and re-usable.

提交回复
热议问题