'BaseXml' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit
定义了一个基类,出现了上面的警告,具体的类定义如下:
经过搜索发现原因如下:
If a class is defined in a header file and has a vtable (either it has virtual methods or it derives from classes with virtual methods), it must always have at least one out-of-line virtual method in the class. Without this, the compiler will copy the vtable and RTTI into every .o file that #includes the header, bloating .o file sizes and increasing link times
定义在头文件中的有虚表(这个函数自身有虚函数或者继承的基类有虚函数,这个类就有虚表)的类,必须至少有一个外联函数。如果没有,编译器就会在包含该头文件的.o目标文件中复制虚表和运行时类型标识,这将会导致目标文件大小的膨胀和链接次数的增加。
找到了原因之后修改代码,告警消失。
虽然一些小的告警一般不会影响代码的运行,但是在特定情况下,该问题所产生的影响将会被放大显露出来。所以平时在写代码时应该养成好的习惯,搞清楚每个告警后面的原因,追求0告警,不为代码埋雷。