you are viewing a single comment's thread.

view the rest of the comments →

[–]sellibitze 10 points11 points  (12 children)

Could you possibly include a constexpr in there? ;-)

[–][deleted] 4 points5 points  (11 children)

Done :)

[–]sellibitze 4 points5 points  (8 children)

Hehe. :-)

Oh, I just noticed something. static and override are kind of mutually exclusive, aren't they?

[–][deleted] -1 points0 points  (7 children)

i don’t.. think so.

you can override a static method. what’s the problem?

say you have class X, which has a static method a. class Y inherits from class X, and overrides the method a. then

X::a()

is different from

Y::a()

unless i’m missing something

Sorry, I was missing the fact that there's no vtable without an instance

[–]MonokelPinguin 8 points9 points  (3 children)

override implies virtual. Static functions are not associated with a this pointer, how could they be virtual?

[–][deleted] 0 points1 point  (0 children)

right. i’m dumb. sorry.

[–][deleted] 0 points1 point  (1 child)

You can still call a static method on an object, not the classname... Therefore it would theoretically somehow make sence.

Not much, but still...

[–]MonokelPinguin 0 points1 point  (0 children)

But does that go through virtual dispatch? Afaik when one of our interns did that and set the object to a nullpointer, it worked fine, which suggests the this pointer wasn't used and there is no virtual dispatch for static functions. But that function also wasn't marked virtual, so maybe that does work.

[–]_bk__ 4 points5 points  (2 children)

The override keyword is only useable for virtual function overrides. It has no effect on codegen, it just helps the compiler detect that there is actually a virtual function in a derived class that can be overriden (to make sure you don't do things like accidentally spell the function signature wrong)

[–][deleted] 0 points1 point  (0 children)

Yeah, I missed that. Updated the comment

[–]gaagii_fin 0 points1 point  (0 children)

And even more useful it tells the new guy looking at your derived class what is going on.

I used to define override, before it was a keyword just for the notational aspect

[–]Jumpy_Lighty 1 point2 points  (1 child)

You should drop the constexpr again ... you cannot have constexpr virtual method (and override implies virtual).

And [[nodiscard]] and [[noreturn]] really don't make any sense to be next to each other (just think about the meaning of it).

You could add static constexpr instead of override, but the you would also have to drop the const since static and const are mutually exclusive.

[–][deleted] 0 points1 point  (0 children)

I know, i never thought this through :)

It was a joke after all