I have a C++ class (Class D) that is a decorator of another class (Class B). Class D inherits from B and also requires an instance of B to construct that it keeps track of. Class D overrides all methods in B and instead calls the same functions on it's own instance of B. My worry is in maintaining this. If someone edits class B and adds a new function, they need to ensure that they add that function to class D as well, or it will break the pattern. Is there a way I can check at compile time that class D overrides all methods from class B? I'm working in C++.
Code sample:
class B
{
public:
B();
void methodA() {std::cout << "A" << std::endl;};
void methodB() {std::cout << "B" << std::endl;};
};
class D : public B
{
public:
D(B* b)
{
bptr_ = b;
}
void methodA() override
{
bptr_->methodA();
}
void methodB() override
{
bptr_->methodB();
}
void specialDFunction() {/*do something*/};
private:
B* bptr_;
}