How do I achieve the desired output via suitable modification of any code except Derived::Derived()
?
#include<iostream>
std::ostream& o = std::cout;
struct Base
{
void sanitycheck() { o << "base checks\n"; }
Base() { o << "make base\n"; }
};
// Code of struct Derived shall remain unaltered
struct Derived : Base
{
Derived() { o << "make derived\n"; }
};
// Dummy might help?
struct Dummy
{
Base& base;
Dummy(Base& base) :base(base) {}
~Dummy() { base.sanitycheck(); }
};
int main()
{
Derived x;
/* desired output:
make base
make derived
base checks // <-- missing piece
*/
}
Background: Base is in a library. Derived is user-supplied. Sanity checks can help mitigate user errors.