Change Protected Method From Abstract Class to Private In Concrete Class

I want to create an abstract class with a pure virtual private method but I can't implement that in my concrete class. My option is to make that pure virtual private method to protected but in my concrete class I want to make it only a private. Like,

class IFoo
{
public:
    IFoo(){}
    virtual ~IFoo(){}

protected:
    virtual void fooMethod() = 0;
};

class Foo : public IFoo
{
public:
    Foo(){}
    virtual ~Foo(){}

private:
    virtual void fooMethod() {}
};

Is there any implication doing this? Or this is just fine?

Thanks!


Why can't you make the method private in the base class? Making them private is a pretty standard design pattern for C++. Then the base class implements public/protected methods that call the private ones.

http://www.gotw.ca/publications/mill18.htm has way more info on the uses of public/private/protected virtual methods.

链接地址: http://www.djcxy.com/p/27732.html

上一篇: 抽象类或使用接口的公共方法

下一篇: 将受保护的方法从抽象类更改为私有混凝土类