mercredi 21 mars 2018

ampersand operation on non-static member

I ran into this code while reading this book:

// define binary tree structure and traverse helpers:
struct Node {
    int value;
    Node* left;
    Node* right;
    Node(int i=0) : value(i), left(nullptr), right(nullptr) {}
    ...
};
auto left = &Node::left;
auto right = &Node::right;

I would like to ask what does the line auto left = &Node::left; mean? Clearly, Node::left is not a static class member, so how is it possible to obtain its address via the & operator? As a follow-up question, what is the type deduced by auto? Node**?

Aucun commentaire:

Enregistrer un commentaire