c++ - Where to allocate one time use class? -


lets consider following code:

void main(int argc, char* argv[]) { foo foo; //at point don't need foo more //a lot of stuff here } 

if need foo short amount of time,isn't better allocate on heap , delete before executing rest of code?

no, it's better write inner scope.

int main() {     {         foo foo;         // use foo     }     // more code } 

but doing should hint might better put foo in separate function.

there's no reason use heap allocation here though. solution worse problem.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -