将我的VC ++项目从VS2015升级到VS2017之后,使用VS2015构建时没有构建错误。 VS2017出现以下构建错误:
(217):错误C2678:二进制'*':未找到采用'const _Iter'类型的左操作数的运算符(或没有可接受的转换)
有问题的行是:
std::vector <WeakRef <int> > vc (weakref_adaptor (v.begin()), weakref_adaptor (v.end()));
WeakRef和weakref_adaptor的定义如下:
template <class T>
class WeakRef
{
public:
explicit WeakRef (T* t)
: _ref (t)
{}
WeakRef (const WeakRef& r)
: _ref (r._ref)
{}
WeakRef& operator = (const WeakRef& r)
{
_ref = r._ref;
return *this;
}
~WeakRef ()
{
// Quite specifically, nothing to do: certainly not deleting _ref!
}
T& operator * () const
{
return *_ref;
}
T* operator -> () const
{
return _ref;
}
private:
T* _ref;
};
template < class Iterator, class Value = typename Iterator::value_type >
class weakref_adaptor_t
{
public:
typedef typename Iterator base_iterator;
typedef WeakRef <typename Value> value_type;
typedef typename base_iterator::difference_type difference_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef std::forward_iterator_tag iterator_category;
weakref_adaptor_t (const base_iterator& base)
: _base (base)
{};
value_type operator * ()
{
return value_type (&(*_base));
}
private:
base_iterator _base;
};
template <class Iterator>
weakref_adaptor_t <Iterator> weakref_adaptor (const Iterator& i)
{
return weakref_adaptor_t <Iterator> (i);
}
template <class Iterator>
weakref_adaptor_t <Iterator, const typename Iterator::value_type>
const_weakref_adaptor (const Iterator& i)
{
return weakref_adaptor_t <Iterator, const Iterator::value_type> (i);
}
};