返回 *这会给出 Weffc++ 警告
returning *this gives Weffc++ warning
我这里有一些代码,我正在使用-Weffc++ -Wall -Wextra编译。
基本上我有这个片段:
class base
{};
class test : public base
{
public:
base& operator=(int)
{
return *this;
}
};
我得到警告:warning: 'operator=' should return a reference to '*this' [-Weffc++]
.我真的不确定该如何看待这个警告。我已经读到这是完全可以的(即返回一个尊重这个(。
有没有办法让我的顺从者满意?
将代码更改为:
class test : public base
{
public:
test& operator=(int)
{
return *this;
}
};
每个人都会很高兴,而不仅仅是你的编译器。
PS:如果你想了解更多,-Weffc++产生的警告是本书中建议的摘录:
有效C++:改进程序和设计的55种具体方法, 艾迪生-韦斯利,1992年,(国际标准书号0-321-33487-6(。
相关文章:
- 警告处理为错误这里有什么问题
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- cppcheck在const std::string[]上引发警告
- GCC对可能有效的代码抛出init list生存期警告
- 如何在BST的这个简单递归实现中消除警告
- 关于std::move的使用,是否有编译警告
- g++ 在某个类成员未初始化时不发出警告
- 如何处理来自核心指南检查器的关于gsl::at的静态分析警告
- 使用typeid警告未使用的变量
- 示例C++项目编译中的警告
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- 如何修复编译器警告 C6386 和 C6385?
- 返回语句后的代码,没有警告
- 获取隐式转换溢出从无符号到已签名的警告
- 编译器警告:执行到达值返回函数的末尾而不返回值
- 在未链接的部分上生成警告
- 警告 C4552:">>":未使用表达式的结果
- 返回 *这会给出 Weffc++ 警告
- C++-带有指针的Weffc++警告
- -Weffc++ 关于具有shared_ptr的简单结构的警告