Overriding private virtual functions

Vladimir Prus ghost at cs.msu.su
Mon Nov 24 05:34:15 UTC 2008


On Monday 24 November 2008 04:29:21 Hamish Rodda wrote:
> SVN commit 888217 by rodda:
> 
> Don't offer to override private virtuals in superclasses
> 
> 
>  M  +9 -10     overridespage.cpp  
> 
> 
> --- trunk/KDE/kdevplatform/language/codegen/overridespage.cpp #888216:888217
> @@ -163,12 +163,6 @@
>  
>  void OverridesPage::addPotentialOverride(QTreeWidgetItem* classItem, KDevelop::Declaration* childDeclaration)
>  {
> -    QTreeWidgetItem* overrideItem = new QTreeWidgetItem(classItem, QStringList() << childDeclaration->toString());
> -    overrideItem->setFlags( Qt::ItemFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable) );
> -    overrideItem->setCheckState( 0, Qt::Unchecked );
> -    overrideItem->setIcon(0, DUChainUtils::iconForDeclaration(childDeclaration));
> -    overrideItem->setData(0, Qt::UserRole, QVariant::fromValue(IndexedDeclaration(childDeclaration)));
> -
>      QString accessModifier;
>      if (ClassMemberDeclaration* member = dynamic_cast<ClassMemberDeclaration*>(childDeclaration)) {
>          switch (member->accessPolicy()) {
> @@ -181,12 +175,17 @@
>                  break;
>  
>              case Declaration::Private:
> -                accessModifier = i18n("Private");
> -                break;
> +                // You can't override a private virtual in a superclass
> +                return;

Can you clarify? Overriding a private function is allowed I think, try compiling
this program:

class B
{
public:
    void do_that() { xdo_that(); }
private:
    virtual void xdo_that() {}
};

class D : public B
{
private:
    virtual void xdo_that() {}
};

Of course, this is questionable design, but it's possible. Are you sure no
user will miss this option?

- Volodya




More information about the KDevelop-devel mailing list