How to detect if a method is virtual?

后端 未结 2 1148
情书的邮戳
情书的邮戳 2020-12-08 00:37

I tried to make a traits to find if a method is virtual: (https://ideone.com/9pfaCZ)

// Several structs which should fail depending if T::f is v         


        
2条回答
  •  执笔经年
    2020-12-08 01:40

    There is probably no way to determine if a specific method is virtual. I say this because the Boost project researched traits for years and never produced such a traits test.

    However, in C++11, or using the Boost library, you can use the is_polymorphic<> template to test a type to see if the type has virtual functions. See std::is_polymorphic<> or boost::is_polymorphic<> for reference.

提交回复
热议问题