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

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

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

keyboard - Smiles and long press feature in Android -