dimanche 1 mars 2015

Should I use a pointer to an object or an object when the object represents an hardware component?


I have a class called Camera which opens a camera with v4l2_open, etc., in the constructor. The destructor does some cleaning and closes the file descriptor with v4l2_close.


When the camera crashes, what I do is to delete the object and then create a new one:



Camera *camera = new Camera();
(...)
if (crash) {
delete camera;
camera = new Camera();
}


Is this one of the correct uses of new/delete in C++?




Aucun commentaire:

Enregistrer un commentaire