禁用有关显式初始化派生类的拷贝构造函数内的基构造函数的警告 [英] Disable warning about explicitly initializing base constructor inside copy constructor of derived class

查看:251
本文介绍了禁用有关显式初始化派生类的拷贝构造函数内的基构造函数的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用启用了-Wextra的g ++版本4.2.1。我包含库中的头文件,并且我一直收到以下有关库中类的警告,这是由-Wextra(我用BaseClass替换了类的实际名称)启用的:

 警告:基类'class BaseClass'应该在复制构造函数中显式初始化

我的问题是:如何禁用此警告?例如,-Wextra也启用了-Wuninitialized,但是我可以通过将-Wno-uninitialized作为编译器标志进行传递来覆盖该简单代码。是否有类似的复制构造函数的警告?我无法在g ++手册页或任何其他论坛帖子中找到答案。 解决方案

根据 http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html (搜索 Wextra ),它是 -Wextra 的固有部分,不能单独禁用(例如它并不是通过它自己的 -W 选项单独列出的)。



它看起来像你能做的最好的事情是或者将该库的使用分离到一个文件,在该文件中禁用 -Wextra 或不要使用 -Wextra 在全部并单独启用其所有组件(从该链接)。


I'm using g++ version 4.2.1 with -Wextra enabled. I'm including a header from a library, and I keep getting the following warning about a class in the library, which is enabled by -Wextra (I've replaced the class's actual name with BaseClass):

warning: base class ‘class BaseClass’ should be explicitly initialized in the copy constructor

My question is: how can I disable this warning? For example, -Wextra also enables -Wuninitialized, but I can override that simple by passing -Wno-uninitialized as a compiler flag. Is there anything similar for the warning about the copy constructor? I wasn't able to find the answer in the g++ manpages or in any other forum posts.

解决方案

According to http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html (search for Wextra) that is an inherent part of -Wextra and can't be disabled separately (e.g. it isn't listed separately by its own -W option).

It looks like the best you can do is either isolate the use of the library to one file on which you disable -Wextra or don't use -Wextra at all and individually enable all its components (from that link).

这篇关于禁用有关显式初始化派生类的拷贝构造函数内的基构造函数的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆