I have a class hierarchy similar to this:
struct VideoCapture { virtual open(const string& uri) = 0; virtual close() = 0; };
struct VideoCapture1 : public VideoCapture {...};
struct VideoCapture2 : public VideoCapture {...};
struct VideoCapture3 : public VideoCapture {...};
I added the following constructor and destructor in each of these classes:
VideoCaptureN(const string& uri) { open(uri); }
~VideoCaptureN() { if (!isOpen()) { close(); } }
Though, providing RAII this did not pass the code review as I had to duplicate the same exact code in every classes.
What would be the solution to get RAII and avoid code duplication?