这六种方法(实际上是三种,实际发出警告的方法是非const版本)导致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();
}
答案 0 :(得分:1)
如ildjarn所述,警告是acknowledged错误。如果你看一下与你的代码类似的最基本用法的代码,则没有以下警告(并且不是递归的)。
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;
}