0
template <class T>
struct BinaryTreeNode
{
    T data_;

    BinaryTreeNode* left_;
    BinaryTreeNode* right_;
};


template <class Node>
class TreeItBase : public boost::iterator_facade<
        TreeItBase<Node>,
        Node,
        boost::forward_traversal_tag
        >
{
public:
    TreeItBase()
        : nodePtr_(0L) {}

    explicit TreeItBase(Node* node)
        : nodePtr_(node) {}

protected:
    friend class boost::iterator_core_access;

    template <class OtherNode>
    bool equal(const TreeItBase<OtherNode>& other) const
    { return nodePtr_ == other.nodePtr_; }

    virtual void increment() = 0;

    Node& dereference() const
    { return *nodePtr_; }

    Node* nodePtr_;
    std::stack<Node*> stack_;
};


template <class Node>
class PreOrderIt : public TreeItBase<Node>
{
private:
    void increment()
    { this->nodePtr_ = this->nodePtr_->right_; } // Ignore the logic error
};

我正进入(状态,

error: invalid operands to binary expression ('BinaryTree<int>::PreIt'
(aka 'PreOrderIt<BinaryTreeNode<int> >') and 'PreIt'
(aka 'PreOrderIt<BinaryTreeNode<int> >'))

这是完整的错误(pastebin)

编辑

这是我的BinaryTree课,

template <class T>
class BinaryTree
{
public:
    typedef TreeItBase< BinaryTreeNode<T> > It;
    typedef PreOrderIt< BinaryTreeNode<T> > PreIt;

    void Insert(const T& data);
    void Erase(It& it);

    PreIt PreOrderBegin();
    PreIt PreOrderEnd();
};

这是我的main()

int main()
{
    BinaryTree<int> tree;

    for (BinaryTree<int>::PreIt it = tree.PreOrderBegin();
        it != tree.PreOrderEnd(); ++it)
    {
        std::cout << *it << ", ";
    }
    std::cout << "\n";

    return 0;
}

解决方案

改为virtual void increment() = 0

virtual void increment()
{}

感谢大家的帮助,:)

4

0 回答 0