Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark overridden functions

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.

like image 896
Theo Avatar asked May 12 '12 09:05

Theo


2 Answers

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.

like image 171
rve Avatar answered Sep 24 '22 12:09

rve


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

like image 37
Daniel Illescas Avatar answered Sep 24 '22 12:09

Daniel Illescas