Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSlig Commando

Posted 15 May 2013 - 08:24 PM

void frobnicate()
{
    CFoobar *foo = new CFoobar();
    
    //Fixed
    int* var = foo->GetFoo();
    *var += 7;

    double thing = *foo->GetBaz();
    // etc...
    
    delete foo;
}

 

Honestly I like returning pointers for most cases. Using the pointer you dont have to make a thousand function calls. Especially in parallel programming this is very useful when you want to avoid static variables. Sometimes its not a good idea, or not even possible depending on the use, but I believe this is a perfectly valid programming habit. IMO


#1Slig Commando

Posted 15 May 2013 - 08:22 PM

void frobnicate()
{
    CFoobar *foo = new CFoobar();
    
    //Fixed
    int* var = foo->GetFoo();
    *var += 7;

    // Wow! This is much easer than writing foo->setFoo(foo->getFoo()+7);
    //*foo->GetFoo() = *foo->GetFoo()+7;

    double thing = *foo->GetBaz();
    // etc...
    
    delete foo;
}

 

Honestly I like returning pointers for most cases. Sometimes its not a good idea but I believe this is a perfectly valid programming habit. IMO


PARTNERS