Let us suppose there exists a base class with a virtual method:

class BaseClass
{
    virtual void MethodToOverride() const
    {
        DoSomething();
    }
};

Along with a derived class which overrides the technique (with respect to the situation we makes it again virtual or otherwise):

class DerivedClass : public BaseClass
{
    void MethodToOverride() const
    {
        DoSomethingElse();
    }
}

When we get it wrong, for instance determining the MethodToOverride non const or having a wrong character, we just define a brand new method, for instance:

void MethodToOverride() {} // I forgot the const 
void MthodToOverride() const {} // I made a typo

Which means this compiles fine, but causes undesirable behavior at runtime.

Can there be in whatever way to define a work as an explicit override of the existing one, therefore the compiler alerts me basically define it wrongly? Something similar to (Yes, it doesn't exist):

void MethodToOverride() const overrides BaseClass::MethodToOverride() const {} 

The easiest way would be to declare the technique to become pure virtual in BaseClass.

class BaseClass 
{ 
    virtual void MethodToOverride() const = 0;
};

If applying courses are inherited again (that we would place in question like a semi sound practice), there's not a way to manage the right implementation.

[[override]] attribute. Yet it's part of C++0x.

If you work with gcc think about the -Woverloaded-virtual command-line option.

C++0x provides an attribute with this (see vitaut's answer), and e.g. Visual C++ provides a language extension.

However in portable C++98 the very best you should do is a sanity check, the base class provides an accessible member function that accepts exactly the same arguments, like ...

// The following macro is mainly comment-like, but performs such checking as it can.
#define IS_OVERRIDE_OF( memberSpec, args ) \
    suppressUnusedWarning( sizeof( (memberSpec args, 0) ) )

where

template< typename T >
inline void suppressUnusedWarning( T const& ) {}

You call the macro inside your override implementation, using the function's actual arguments.

EDIT Added call example (disclaimer: untouched by compiler's hands):

class BaseClass
{
protected:
    virtual void MethodToOverride() const
    {
        DoSomething();
    }
};

class DerivedClass : public BaseClass
{
protected:
    void MethodToOverride() const
    {
        IS_OVERRIDE_OF( BaseClass::MethodToOverride, () );
        DoSomethingElse();
    }
};

Using this type of sanity check can enhance the clearness from the code in some cases, and may save your valuable ass in some cases. It's three costs. (1) Another Person might mistake it for any guarantee, as opposed to just an interesting comment and partial check. (2) the member function can not be private within the base class, because it is inside your example (although that's possibly positive). (3) Many people react intuitively adversely to the utilization of macros (they have just commited to memory a guide about badness without understanding it).

Cheers &lifier hth.,