0

How would I implement an aggregation relationship with the possibility to navigate from a child object to its parent object?

Do I need to use forward declaration?

3

1 Answer 1

1

Yes you do.

struct Node;

struct Aggregator {
    Node* parent;

    Node aggregated1, aggregated2;
};

struct Node {
    Aggregator* aggregated_by;
};

Though with nested types you might be able to dodge it, or if the parent has the same type:

struct Node {
    Node* parent;

    Node aggregated1, aggregated2;
};
0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.