答案 0 :(得分:0)
原因实际上是来自提升类型特征的is_virtual_base_of
检查。如果检查成功,此检查构造将生成警告C4250,如此示例所示:
...
struct base {
virtual void mf() { };
};
struct derived_normal : public base {
virtual void mf() { };
};
struct derived_virt : virtual public base {
virtual void mf() { };
};
int main() {
using namespace std;
cout << "boost::is_virtual_base_of<base, derived_normal>::value reports: ";
// The following line DOES NOT cause C4250
cout << boost::is_virtual_base_of<base, derived_normal>::value << endl;
cout << "boost::is_virtual_base_of<base, derived_virt> reports: ";
// The following line causes C4250:
cout << boost::is_virtual_base_of<base, derived_virt>::value << endl;
...
FWIW,这种类型特征工具在boost序列化中的用法如下:
BOOST_EXPORT_CLASS
- &gt;
BOOST_CLASS_EXPORT_IMPLEMENT
- &gt;
struct guid_initializer
(在export.hpp中) - &gt; void_cast_register
- &gt; is_virtual_base_of在这里使用据我所知,警告在这种情况下是完全无害的,可以通过将标题包装在:
来防止#pragma warning( push )
#pragma warning( disable : 4250 ) // C4250 - 'class1' : inherits 'class2::member' via dominance
#include ...
#pragma warning( pop ) // C4250