This code sample uses the attributes from the preceding examples. It shows you how to create groups that can be inherited, handle change notification, and manipulate group hierarchies.
TInheritableGroupHandle grandParent;
TInheritableGroupHandle parent;
TInheritableGroupHandle child;
// The next call causes NotifyChanged to be called on child, since its
// hierarchy changed.
child.SetParent(&parent);
// The next call causes NotifyChanged to be called on both parent and child,
// since the hierarchy changed for them both.
parent.SetParent(&grandParent);
// The next call causes NotifyChanged() to be called on grandParent, parent
// and child.
grandParent.Add(oneA);
// The next call begins change batching for child and its ancestors.
// That is, changes to child, parent, or grandParent does not result in
// NotifyChanged() being called on any of these.
child.BeginChanges();
parent.Add(twoB);
child.Add(oneC);
count = grandParent.Count(); // Should be 1.
count = grandParent.CountAllInherited(); // Should be 1.
count = parent.Count(); // Should be 1.
count = parent.CountAllInherited(); // Should be 2.
count = child.Count(); // Should be 1.
count = child.CountAllInherited(); // Should be 2, child's "one C" overrides
// grandparent's "one A".
// The next call causes NotifyChanged() to be called on "child,"
// "parent," and "grandParent."
// Note that you must call EndChanges() on the same instance that you called
// BeginChanges() on.
child.EndChanges();