2017-11-16 8 views
-1

コンパイルするときにプロジェクトに問題があります。私はDev c++に同じプロジェクトをコンパイルし、フラグc++11を使用する場合、私はVisual Studio 2015 C++プロジェクトエラーC++ 11標準

error C2039: 'ClusterQuality': is not a member of 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<Granule<std::vector<spare::RealType,std::allocator<T>>>>>>'  

しかし、私は、Visual Studio 2015を使用するとエラーが表示されたコードは次のとおりです。

template <typename AtomicElement> 
class Granule { 
public: 

typedef spare::Sequence<AtomicElement> RepresentantType; 

unsigned int   SymbolID; // identifier of the symbol 
unsigned int    Occurrences; // occurrences of the symbol 
spare::RealType     CompCost; // compactness cost 
spare::RealType     Cost;  // total cost 
spare::RealType     CardCost; // cardinality/size cost 
spare::RealType    Part;  // index of partition of the symbol 
spare::RealType    Clust;  // index of the cluster of the symbol 
spare::RealType     CardClust; // cardinality of the cluster of the symbol 
std::vector<spare::RealType> ThetaVec; // vector for theta values 

    /* 
    * Default constructor 
    */ 
    Granule() {} 

    /* 
    * Constructor prototype 
    */ 
    Granule(typename spare::Sequence<AtomicElement>& rPrototype, 
      spare::RealType aRecogThreshold, 
      spare::RealType aClusterQuality) { 

     if (rPrototype.size()==0) { 
      throw std::logic_error("Empty prototype."); 
     } 

     if ((aRecogThreshold < 0) || (aRecogThreshold > 1)) { 
      throw std::logic_error("Invalid DistThreshold."); 
     } 

     if ((aClusterQuality < 0) || (aClusterQuality > 1)) { 
      throw std::logic_error("Invalid ClusterQuality."); 
     } 

     // Initialization 
     mPrototype= rPrototype; 
     mRecogThreshold= aRecogThreshold; 
     mClusterQuality= aClusterQuality; 
    } 


    /* 
    * Constructor with prototype defined through iterator 
    */ 
    Granule(typename spare::Sequence<AtomicElement>::const_iterator iBegin, 
      typename spare::Sequence<AtomicElement>::const_iterator iEnd, 
      GdsReal aTheta, 
      GdsReal aBeta) { 

     if (iBegin >= iEnd) { 
      throw std::logic_error("Invalid iterators."); 
     } 

     if ((aTheta < 0) || (aTheta > 1)) { 
      throw std::logic_error("Invalid Theta."); 
     } 

     if ((aBeta < 0) || (aBeta > 1)) { 
      throw std::logic_error("Invalid Beta."); 
     } 

     // Assign 
     mPrototype.assign(iBegin, iEnd); 
     mRecogThreshold= aTheta; 
     mClusterQuality= aBeta; 
    } 


    // Prototype definition through iterators 
    typename spare::Sequence<AtomicElement>::const_iterator begin() const { return mPrototype.begin(); } 

    typename spare::Sequence<AtomicElement>::const_iterator end() const { return mPrototype.end(); } 

    // Prototype size 
    typename spare::Sequence<AtomicElement>::size_type size() const { return mPrototype.size(); } 


    // Access to Prototype 
    const typename spare::Sequence<AtomicElement>& Prototype() const  { return mPrototype; } 
    // Access to Prototype 
    typename spare::Sequence<AtomicElement>& Prototype()   { return mPrototype; } 

    // Access to RecogThreshold 
    const spare::RealType& RecogThreshold() const { return mRecogThreshold; } 

    // Access to ClusterQuality 
    const spare::RealType& ClusterQuality() const { return mClusterQuality; } 
    // Access to RecogThreshold 
    spare::RealType&   RecogThreshold()  { return mRecogThreshold; } 

    // Access to ClusterQuality 
    spare::RealType&   ClusterQuality()  { return mClusterQuality; } 

private: 


    // Structure that represents the symbol 
    typename spare::Sequence<AtomicElement> mPrototype; 

    // Recognition threshold 
    spare::RealType       mRecogThreshold; 

    // Symbol quality 
    spare::RealType       mClusterQuality; }; 

    // Symbols ordering criteria 
    template <class StructureType> 
    inline bool operator<(const StructureType& S1, const StructureType& S2) { 
      return (S1.ClusterQuality() > S2.ClusterQuality()); 
    } 

私はコンパイル時にエラーがありますこのエラーはありません。

どうすればこの問題を解決できますか?私はビジュアルスタジオを使用する必要があります。

+0

を追加しましたか?あなたは '顆粒 'をどうやって作りますか? 「なぜ、このコードは動作していない」などの – doctorlove

+0

質問は、問題を再現するために必要な最小限のコードを持っている必要があります。 [mcve]を作ってみてください。 – AndyG

答えて

1

あなたの問題は、operator<がグローバルで広すぎるということです。私はどこかのベクトルを繰り返し、要素を比較するコードを持っていると仮定します。

template <class StructureType> 
inline bool operator<(const Granule<StructureType>& S1, const Granule<StructureType>& S2) { 
    return (S1.ClusterQuality() > S2.ClusterQuality()); 
} 

または類似のもの。

ここにはhttps://godbolt.org/g/3AR6kdを再現できます。私はちょうど

ライン
int main() 
{ 
    std::vector<int> t2; 

    if (t2.end() < t2.begin()) 
    { 
    } 

    return 0; 
} 
+0

私はOPはMCVEを提供するまで、私たちは本当に言うことはできませんが、あなたの推理は、正しいことを疑います。余談として、OPの 'Granule'クラスがテンプレートであることに注意してください。 – AndyG

関連する問題