C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Calling methods on a nullptr

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 28 Oct 2024 11:45:30 +0000
On Mon, Oct 28, 2024 at 8:08 AM Jens Maurer wrote:
>
> And
>
> T *p = nullptr;
> static_cast<T&>(*p).f();
>
> would also be ok, despite the fact that empty lvalues don't exist?


Are you really saying that the following "Hello World" program is okay?

#include <iostream>

struct T {
    static void f(void) { std::cout << "Hello World\n"; }
};

int main(void)
{
    T *p = nullptr;
    static_cast<T&>(*p).f();
}

Received on 2024-10-28 11:45:40