C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Not quite a template virtual function

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 2 Oct 2024 15:13:59 +0100
On Wed, Oct 2, 2024 at 11:25 AM Jonathan Wakely wrote:
>
> It would be technically possible to make this work in very limited circumstances.
> But it would be fragile and fail in most cases. Why bother making a complex
> change that can only be used in very limited ways, for very limited benefit?
> The pros do not outweight the cons.
>
> Once again, this is just "I thought of a thing, let's waste time talking about it".


It would be nice to have in C++ something like the following:

class Derived : public Base {
    override
    {
        Log( string("Method invoked: Base::") + _Base_func_name );
        auto retval = this->Base::_Base_func(...);
        Log( string("Method returned with retval = ") + to_string(retval) );
        return;
    }
};

The above class can be used to log all calls to the Base class's
methods (both virtual and non-virtual) without knowing anything about
the Base class.

Received on 2024-10-02 14:14:11