我在编译项目时遇到问题。我使用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());
}
当我编译错误是:
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>>>>>>'
但是,如果我在
Dev c++
上编译相同的项目并使用c++11
标志,则不会出现此错误。我怎么解决这个问题?我必须使用Visual Studio。
最佳答案
您的问题是您的operator<
是全局的并且太宽泛。我假设您在某处具有在 vector 上迭代并比较元素的代码。
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;
}
关于c++ - Visual Studio 2015 C++项目错误C++ 11标准,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47327736/