使用enum/int覆盖函数

Cha*_*hap 3 c++ compiler-construction inheritance enums

如果有一个具有函数的基类DeriveMe virtual void DoSomething(int)和一个继承DeriveMe的类,它具有一个函数void DoSomething(SomeEnum)DerivedThat ...... DerivedThat是否会覆盖基类DoSomething,因为枚举在C++的编译期间计算为整数?

我可以尝试通过使DoSomething纯虚拟并编译/运行它来查看它是否有效但这是我的第一个stackoverflow问题所以我宁愿问它.

gre*_*ade 8

不,DerivedThat将从基类隐藏函数,因为签名不匹配.enums 评估int,因为它们是一种独特的类型.

请参阅C++ FAQ,第23.929.19节.