C++ Visual Studio 2010 C4717 编译器警告在代码的一部分,但不在另一部分
C++ Visual Studio 2010 C4717 compiler warning in one part of code but not in another
这六个方法(实际上是三个,实际抛出警告的是非常量版本)导致 C4717(所有路径上的函数递归)警告,但遵循这些方法的方法没有(与我能说的完全相同......我错过了什么导致这些警告而不是另一个警告?
警告生成方法:
template<class T>
const QuadTreeNode<T>* QuadTree<T>::GetRoot() const {
return _root;
}
template<class T>
QuadTreeNode<T>* QuadTree<T>::GetRoot() {
return static_cast<const QuadTree<T> >(*this).GetRoot();
}
template<class T>
const int QuadTree<T>::GetNumLevels() const {
return _levels;
}
template<class T>
int QuadTree<T>::GetNumLevels() {
return static_cast<const QuadTree<T> >(*this).GetNumLevels();
}
template<class T>
const bool QuadTree<T>::IsEmpty() const {
return _root == NULL;
}
template<class T>
bool QuadTree<T>::IsEmpty() {
return static_cast<const QuadTree<T> >(*this).IsEmpty();
}
非警告生成方法:
template<class T>
const Rectangle QuadTreeNode<T>::GetNodeDimensions() const {
return _node_bounds;
}
template<class T>
Rectangle QuadTreeNode<T>::GetNodeDimensions() {
return static_cast<const QuadTreeNode<T> >(*this).GetNodeDimensions();
}
正如ildjarn所提到的,这是一个带有警告的公认错误。如果您以与代码类似的最基本用法查看代码,则不会发出以下警告(并且不是递归的)。
class A
{
public:
bool IsEmpty()
{
return static_cast<const A>(*this).IsEmpty();
}
bool IsEmpty() const
{
return true;
}
};
int main()
{
A whatever;
whatever.IsEmpty();
return 0;
}
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual C++ constexpr Hints
- 为什么它不适用于Visual 2019的原因
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- visual在c++中将十进制数转换为二进制数
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- C++:如何使函数只返回作为列表一部分的字符串
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual C++(VS2017)中用户定义的转换不明确
- Visual C++GC接口如何启用它以及要包含哪个库
- C++/WinRT,Windows SDK 17134的一部分与Visual Studio 15.8 Preview 3
- strcpy_s是C++标准的一部分吗?或者只是MS Visual C++的一部分
- C++ Visual Studio 2010 C4717 编译器警告在代码的一部分,但不在另一部分