are there any tricks to override private or protected methods in a base class with CRTP without changing visibility
template<typename Derived>
class Base {
void foo() { std::cout << "Base::foo\n"; static_cast<Derived*>(this)->foo(); } // private
public:
void bar() { this->foo(); } // part of the public interface
};
class Derived : public Base<Derived> {
void foo() { std::cout << "Derived::foo\n"; } // override, still private to match visibility of base interface
};
int main() {
Derived d{};
d.bar(); // error : 'foo' is a private member of 'Derived'
}```
I'm trying to essentially achieve what would otherwise be overriding a private virtual method with CRTP. but of course this doesnt work. I've seen similar-ish SO articles on this topic but the solutions are very complex and not so ideal: https://stackoverflow.com/a/55928800
I was wondering if there were any hidden tricks to achieve this functionality