Why would a virtual function be private?

liori picture liori · Jul 15, 2009 · Viewed 13k times · Source

I just spotted this in some code:

class Foo {
[...]
private:
    virtual void Bar() = 0;
[...]
}

Does this have any purpose?

(I am trying to port some code from VS to G++, and this caught my attention)

Answer

Greg Rogers picture Greg Rogers · Jul 15, 2009

See this Herb Sutter article as to why you'd want to do such a thing.