I'm implementing a static polymorphism:
template<typename T>
class Base {
public:
void method() {
// do something
impl();
// do something else
}
void impl() { // intended to be private
static_cast<T*>(this)->impl();
}
};
class Derived : public Base<Derived> {
public:
void impl() { // intended to be private
}
};
This code is a static implementation of a dynamic polymorphic classes where void impl() was virtual and private.
I've achieved polymorphism (static). But I had to make the method void impl() public in order to allow access to it from a Base class. I want method void impl() to be private again. Can it be done?
UPDATE: I don't want to write
friend class Base<Derived>;
in Derived class, because it allows Base access to all members of Derived.
friend class Base<Derived>
to theDerived
class. – Riddick