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
Post a Comment