Chap
Chap

Reputation: 2796

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.

Upvotes: 3

Views: 1591

Answers (1)

greyfade
greyfade

Reputation: 25657

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.

Upvotes: 8

Related Questions