编译链接实战(19)常见编译链接错误汇总

-Wreorder成员未按顺序初始化

-Wreorder (C++ and Objective-C++ only)
Warn when the order of member initializers given in the code does not match the order in which they must be executed. For instance:

struct A {
  int i;
  int j;
  A(): j (0), i (1) { }
};

The compiler rearranges the member initializers for i and j to match the declaration order of the members, emitting a warning to that effect. This warning is enabled by -Wall.

-Wnon-virtual-dtor持有虚函数却不是虚析构

-Wnon-virtual-dtor (C++ and Objective-C++ only)
Warn when a class has virtual functions and an accessible non-virtual destructor itself or in an accessible polymorphic base class, in which case it is possible but unsafe to delete an instance of a derived class through a pointer to the class itself or base class. This warning is automatically enabled if -Weffc++ is specified.

-Wnon-virtual-dtor是一个编译器选项,用于启用警告,提示开发人员在类中定义了虚函数但没有定义虚析构函数的情况。

在C++中,当一个类有虚函数时,通常也应该有一个虚析构函数。因为如果子类对象被销毁时只调用父类的析构函数,那么可能会导致内存泄漏或者未释放资源的情况发生。

-Wnon-virtual-dtor编译器选项的作用就是让开发人员知道这种潜在的问题,并提示他们修改代码。如果一个类拥有虚函数但没有虚析构函数,编译器将会发出警告信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值