8

Does a command exist, like \deprecated, but to mark overridden functions?

Java has an annotation @override for functions you have overridden. I would like to do the same in C++, so that I can to see the superclass functions I've overridden. At best, the documentation page should also show all class member functions, which are inherited, but not explicitly overridden with hyper-links to the superclass functions.

I know there is a way to copy the documentation from the superclass method. But I don't want to have the whole doc copied. I just want to know, that a function is inherited. The behavior should be similar to the deprecated option to mark those old functions with a bar.

Peter Wood
  • 23,859
  • 5
  • 60
  • 99
Theo
  • 589
  • 7
  • 16

2 Answers2

9

Every overridden function automatically gets a notice it has been reimplemented. For example the overridden function in a derived class gets the notice "Reimplemented from MyBaseClass."

It also puts a notice in the documentation of the base class. There is mentions "Reimplemented in Test"

To show all functions, including the inherited functions, you can set INLINE_INHERITED_MEMB to YES. Then Doxygen copies the documentation of every inherited, but not overridden, function into the documentation of the derived class.

For example, when using this source:

class TestBase
{
    public:
        /**
         * Base class function.
         */
        virtual void function();

      /**
       * Another function.
       */
      virtual void another();
};

class Test: public TestBase
{        
    public:
        /**
         * Overridden function.
         */
        virtual void function();
};

And setting INLINE_INHERITED_MEMB to YES will result in the following documentation for the Derived class: (With Doxygen 1.7.6)

Member Function Documentation

virtual void TestBase::another ( ) [virtual, inherited]
Another function.

virtual void Test::function ( ) [virtual]
Derived.
Reimplemented from TestBase.

I think this is what you are looking for.

albert
  • 8,285
  • 3
  • 19
  • 32
rve
  • 5,897
  • 3
  • 40
  • 64
  • Hi rve, thanks that is a good tip, but not the whole solution for me. If I override my own functions, that's ok, but if I override e.g. a qt function, doxygen doesn't recognize that it is overriden. I also don't get the inherited block in brackets, but just a reimplemented in message. That's ok, but I wish, I could see the overriden status directly in the member list overview. – Theo May 16 '12 at 14:07
  • A bit late, but you can use tag files to let Doxygen know about classes documented elsewhere. If you have a tag file for QT, then (I think) it should mark functions inherited from QT. Never tried it though. – rve Oct 26 '12 at 11:42
1

Since C++11 you can use the override specifier:

class A {
    virtual void jump() = 0;
    void talk() {}
};

class B: public A {
    void jump() const override {...} // Error: B:: jump does Not overrides A:: jump (A::Jump is not const...)
    void jump() override {...} // OK: B:: jump overrides A:: jump
    void talk() override {...} // Error: A::talk is not virtual
};

Original Example and official doc: http://en.cppreference.com/w/cpp/language/override

Daniel Illescas
  • 5,346
  • 3
  • 17
  • 23