C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Derived class's function invokes base class's function

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 6 Apr 2022 21:41:16 +0100
On Wed, Apr 6, 2022 at 9:28 PM Jason McKessonwrote:
>
> You still haven't explained why it's important enough to add this
> complexity to the language, particularly when we have other ways of
> handling the circumstance.


For the timebeing I'm just bouncing ideas around. Actually I
originally thought it might be better to mark the Base class instead
of the Derived class as follows:

class Base {
public:
    void Method(void) continue
    {
        cout << "Base must do something essential here" << endl;
    }
};

class Derived : public Base {
public:
    void Method(void)
    {
        cout << "Derived has a job to do here" << endl;
    }
};


> Also, overloading `continue` for this is not a good idea.


You're right, we should use 'static'. Alternatively we could combine
two keywords together such as "goto continue" or "class continue" or
"goto class continue" or "requires continue". I don't want to use any
combination of 'auto' here though, as that keyword is already
everywhere. Maybe use "requires continue" for the declaration, and
then use "goto continue(...)" for the invocation, as follows:


class Base {
public:
    void Method(void) requires continue
    {
        cout << "Base must do something essential here" << endl;
    }
};

class Derived : public Base {
public:
    void Method(void)
    {
        cout << "Derived has a job to do here" << endl;

        goto continue(...);
    }
};

Received on 2022-04-06 20:41:28