-
user-defined iterator
/usr/include/c++/3.2/bits/stl_iterator.h: In constructor
`__gnu_cxx::__normal_iterator<_Iterator,
_Container>::__normal_iterator(const __gnu_cxx::__normal_iterator<_Iter,
_Container>&) [with _Iter = Expression* const*, _Iterator = Expression**,
_Container = std::vector<Expression*, std::allocator<Expression*> >]':
set.hpp:184: instantiated from `Set<T>::iterator Set<T>::begin() const [with T = Expression]'
expression.cpp:99: instantiated from here
/usr/include/c++/3.2/bits/stl_iterator.h:589: invalid conversion from `
Expression* const* const' to `Expression**'
Line 99 is j = n.begin()
expression.cpp:
Code:
void Expression::substitute(const Set<Expression>& exp, const Set<Variable_Plain>& var) {
Set<Variable_Plain>::iterator i;
Set<Expression>::iterator j;
Set<Expression> n(exp);
Set<Variable_Plain> v(var);
for (i = v.begin(),
j = n.begin();
(i != v.end())
&& (j != n.end());
++i,++j) {
// std::cerr << "beg"<<std::endl;
Factor_Expression f_e(*j);
Variable vv(*i);
algo::for_each(terms.begin(),terms.end(),&Expression::sub_substitute,this,f_e,vv);
// std::cerr << "end"<<std::endl;
}
// std::cerr << "end substitute" << std::endl;
}
set.hpp
line 184: is "i.it = (members.begin());"
Code:
template<typename T>
class Set {
//...
class iterator {
public:
typename std::vector<T*>::iterator it;
public:
//iterator(const typename std::vector<T*>::iterator& i) : it(i) {}
T& operator*() const {
return **it;
}
T operator++() {
++it;
return **this;
}
T& operator++(int) {
it++;
return **this;
}
T operator--() {
--it;
return **this;
}
T& operator--(int) {
it--;
return **this;
}
iterator operator+(int x) const {
iterator i(it);
for (int n=0;n<x;++n)
++i;
return i;
}
const bool operator==(const iterator& i) const {
return (it == i.it);
}
const bool operator!=(const iterator& i) const {
return !(*this == i);
}
iterator operator-(int x) const {
iterator i(it);
for (int n=0;n<x;++n)
--i;
return i;
}
};
//...
iterator begin() const {
iterator i;
i.it = (members.begin());
return i;
}
iterator end() const {
iterator i;
i.it = (members.end());
return i;
}
};
My question is... why is it giving me that error?
invalid conversion from Expression* const* const to Expression**
Wouldn't it cast itself implicitly?
-
Oddly enough, I've dealt with almost identical errors at work lately, and they truly are a pain to debug. The problem (most likely) is this:
Your iterator class is allowed to modify the data it is pointing to. Your begin() function, however, is const. Hence, an internal contradiction (which naturally produces the most undecipherable error message).
As a solution, I'd provide a non-const version of begin and end for your set.
Hope this solves it for you.
Cheers
-
Thanks, I'll try it out tomorrow
I'm suprised someone actually understood my problem... :D