i found this when I used CRTP (curiously recurring template pattern).
template <typename T>
class Base {
private:
void f() {
//when T has its own f(), it calls that
//when T doesn't have, it calls itself, which is invoked recursively
//but i expect the compiler to complain that f() is private when T doesn't have its own f()
static_cast<T*>(this)->f();
}
public:
void g() {
f();
}
};
class Derived : public Base<Derived> {};
I thought i understand public, protected and private, but for this case, it looks like i am wrong. Any explanation is appreciated!