| re: another visibility problem
Imre Palik wrote:[color=blue]
> Hi,
>
> for this code:
>
> template <typename content, typename ptr, typename ref>
> class tree_iterator
> : public std::iterator<std::forward_iterator_tag, content, std::ptrdiff_t,
> ptr, ref>
> {
> node<content> *node_;
> public:
> reference operator*() const {return node_->value;}
> pointer operator->() const {return &(node_->value);}
> };
>
> gcc says
>
> error: ISO C++ forbids declaration of `reference' with no type
> error: expected `;' before "operator"
> error: expected `;' before "pointer"
> error: ISO C++ forbids declaration of `pointer' with no type
> error: expected `;' before "operator"
> error: expected `;' before '}' token
>
> but as far as I understand, this is the intended usage of std::iterator,
> and those names should be visible. Throwing using declarations at the problem
> doesn't seems to help either. Any ideas what am I doing wrong?
>
> Thx
>
> ImRe[/color]
You haven't shown the template for node so I took the liberty of
guessing. Anyway with gcc 3.3 the following appears to compile with no
warnings or errors.
template <typename T>
class node
{
public:
T value;
};
template <typename content, typename ptr, typename ref>
class tree_iterator
: public std::iterator<std::forward_iterator_tag, content,
std::ptrdiff_t,
ptr, ref>
{
node<content> *node_;
public:
typename tree_iterator<content,ptr,ref>::reference operator*()
const {return node_->value;}
typename tree_iterator<content,ptr,ref>::pointer operator->() const
{return &(node_->value);}
};
Hope this helps
JB |