2012-04-10 10 views
3

これらの6つのメソッド(実際には警告をスローするものは非constバージョンです)は、C4717(すべてのパスで再帰関数)警告しかし、これらの次のメソッドは(まったく同じ私が言うことができる...)。 私には何が分からないのですか?C++ Visual Studio 2010 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(); 
} 
+2

この警告はバグであり、偽陽性を報告します。詳細については、[このバグレポート](http://connect.microsoft.com/VisualStudio/feedback/details/522094/)を参照してください。 – ildjarn

+0

@ildjarn:だから...それはちょうど行くでしょうか?コンパイラを騙す方法はありますか? – Casey

+0

バグだからベットはすべてオフです。個人的には、警告が間違っていることを知っていれば、私はそれを抑止します。 – ildjarn

答えて

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; 
} 
関連する問題