C++ Logo

std-proposals

Advanced search

Re: [std-proposals] decltype can access private and protected

From: sasho648 <sasho648_at_[hidden]>
Date: Fri, 25 Mar 2022 20:22:49 +0200
Good idea in my opinion.

On Fri, Mar 25, 2022 at 7:47 PM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:

>
> Normally the behaviour is undefined when you dereference a nullptr, but
> it's allowed with decltype, for example the following is valid code:
>
> decltype( static_cast<std::string*>(nullptr)->compare("Hello") )
> my_var;
>
> ++my_var;
>
> I think decltype should be given another privilege: To get the type of
> protected/private members, for example:
>
> class Dog {
> private:
> int calibration[3u][2u][7u];
> };
>
> int main(void)
> {
> Dog doggy;
>
> decltype(doggy.calibration) my_array;
> }
>
> This past week I was writing code for an Arduino microcontroller to save
> POD's to the onboard non-volatile Flash, and I had to edit a class to
> change a member from protected to public just so that I could use decltype
> on it. This shouldn't be necessary -- just allow decltype to get the type
> of anything irrespective of accessibility.
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2022-03-25 18:23:06