mercredi 13 novembre 2019

In C++ OOP, who is responsible to delete object passed to constructor

For example,

I have an account generator class need a random method to decide username and password. Random has many ways to implement, so it is an interface with many subclass. Account generator class accept Random object in constructor.

In Java we don't care the deletion of object. But I'm now doing it in C++. My question is, if I did the following in main()

Random random=new StdRandom();
AccGen accGen=new AccGen(random);

should I delete "random" in main(), or I should put it in the destructor of AccGen?

Aucun commentaire:

Enregistrer un commentaire