0

I Have a struct Node which has front and back pointers and now I want to define the operator -> to do the following:

it->front //should return the front of the Node that iterator point to
it->back //should return the back of the Node that iterator point to
struct Iterator {
    ...
    // here I want to redefine this operator ->        
    std::shared_ptr<Node> operator->front() {
        return m_ptr->front;
    }
    ...
 }

This is the Node struct:

    struct Node {
        T value;
        std::shared_ptr<Node> front, back;
        Node (T data, std::shared_ptr<Node> ptr, std::shared_ptr<Node> ptr2) 
            : value(data), front(ptr), back(ptr2) {}
    };
    
man
  • 23
  • 5
  • https://stackoverflow.com/questions/10677804/how-arrow-operator-overloading-works-internally-in-c check that question – oubaydos Jul 30 '22 at 14:07
  • Looks like the basic problem is that you are thinking too specifically. You would define `operator ->` as stated in your text, not `operator ->front` as attempted in your code. It's interesting how sometimes thinking generically makes a problem easier to solve. – JaMiT Jul 30 '22 at 15:42

0 Answers0