public テンプレート メソッドを提供するスーパー クラスがあるとします。サブクラスは、いくつかのサブ操作を実装する必要があります。このサブオペレーションを からのみ呼び出すことができるように宣言するにはどうすればよいSuperClass
ですか? がありますがprotected
、私が知る限り、それは逆に機能します。サブクラスは、保護されたスーパークラスのメンバーにアクセスできます。スーパークラス (およびスーパークラスのみ!) がサブクラス メンバーを呼び出せるようにしたいと考えています。
class SuperClass{
public:
void templateMethod(){
this->op1();
this->op2();
}
// how to declare these? public? protected?
virtual void op1() = 0;
virtual void op2() = 0;
}
class SubClass : public SuperClass{
// how to declare these? public? protected?
virtual void op1() { ... };
virtual void op2() { ... };
}
私は現在 C++ と Matlab で作業していますが、他の言語を考慮した一般的な意見にも非常に興味があります。