Not if the purpose of this function is to instantiate some data and transfer it to another object. An example (hypothetical) from the gaming industry:
void AddProjectileAtPoint(int x, int y) { Projectile *p = new Projectile(x, y); mProjectileManager->Add(p);
In this case, the goal is clearly to create a new object representing some data and store it somewhere for later use.
Obviously, at some point it will be necessary to combine delete , but not inside the function where new occurs. This is fine as long as there is a well-defined procedure for transferring responsibility for managing new'd memory for some other component.
In this case, the structure is that the "projectile manager" takes responsibility for all the shells that are given to him, will keep them alive as long as necessary, and will clear his memory when appropriate.
source share