C++ Logo

std-proposals

Advanced search

[std-proposals] explicit this

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 3 Apr 2023 09:32:15 +0100
Sometimes when I'm reading through another person's implementation of
a class, I see function calls inside member functions:

void SomeClass::SomeFunc(void)
{
    SomeOtherFunc();
}

When I first see this code, I don't know if SomeOtherFunc is a member
function, or whether it's a member datum (i.e. a function pointer), or
whether it's a global function.

When I write the implementation of my own classes, I tend to like to
be specific:

void SomeClass::SomeFunc(void)
{
    this->SomeOtherFunc();
}

I was thinking it would be good if we could mark a class, or perhaps
mark a member function, as "explicit this", as follows:

class SomeClass : explicit this {

    void (*SomeOtherFunc)(void);

    void SomeFunc(void)
    {
        SomeOtherFunc(); /* compiler error */
    }
};

Received on 2023-04-03 08:32:24