Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding function with enum/int

If there was a base class DeriveMe that had a function virtual void DoSomething(int) and a class that inherits DeriveMe called DerivedThat that had a function void DoSomething(SomeEnum)...would the DerivedThat override the base class DoSomething because enums evaluate to ints during compile time in C++?

I could try this by making DoSomething pure virtual and compile/run it to see if it works but this is my first stackoverflow question so I'd rather just ask it.

like image 534
Chap Avatar asked Dec 14 '25 19:12

Chap


1 Answers

No, DerivedThat will hide the function from the base class, since the signatures don't match. enums do not evaluate to int, as they are a distinct type.

See the C++ FAQ, sections 23.9 and 29.19.

like image 74
greyfade Avatar answered Dec 16 '25 10:12

greyfade