How to add child layer to parent layer in C++ SDK?

In C++ I am trying to add child layers to a parent layer but so far without success.

I can add one, top layer by calling the function below with, for example:
wchar_t *layer_name = L"House Cloud"

    int32_t add_layer(CRhinoDoc *pDoc, CRhinoLayerTable &layer_table, wchar_t *layer_name) {
    	// Does a layer with the same name already exist?
    	// layer_name = parent::child using ON_Layer::LayerNamePathDelimiter() for :: separator.
    	int32_t layer_index = layer_table.FindLayerFromFullPathName(layer_name, -1);
    	// If so delete it.
    	if (layer_index >= 0) {
    		// Get any objects on the layer
    		const CRhinoLayer &layer = layer_table[layer_index];
    		ON_SimpleArray<CRhinoObject*> obj_list;
    		int i, obj_count = pDoc->LookupObject(layer, obj_list);
    		// Delete all of the layer's objects.
    		CRhinoObject* obj; for (i = 0; i < obj_count; i++) { obj = obj_list[i]; pDoc->DeleteObject(obj); }
    		// Now remove the layer.
    		layer_table.DeleteLayer(layer_index, true); }
    	// Create a new layer for the graph.
    	ON_Layer layer; layer.SetName(layer_name);
    	// Add the layer to the layer table.
    	layer_index = layer_table.AddLayer(layer);
    	// If layer could not be added, layer index will be negative.
    	return layer_index;
    }

but I cannot create a sublayer using:
wchar_t *layer_name = L"House Cloud::Kitchen Cloud"
The result is a layer with the hierarchical names flattened into one name: House Cloud::Kitchen Cloud

There must be a different way to do this.

Regards,
Terry.

I solved the problem of creating sub-layers using this enhanced version of add_layer:

int32_t add_layer(CRhinoDoc *pDoc, CRhinoLayerTable &layer_table, wchar_t *layer_name, wchar_t *parent_name = L"", bool visible = true) {
	// Construct full_name in hierarchical format: parent_name::layer_name
	wchar_t full_name[160];
	if (wcslen(parent_name)) { wcscpy(full_name, parent_name); wcscat(full_name, L"::"); wcscat(full_name, layer_name); }
	else { wcscpy(full_name, layer_name); }
	// Does a layer with the same hierarchical name already exist?
	int layer_index = layer_table.FindLayerFromName(full_name, false, true, -1, -2);
	// If so delete its objects.
	if (layer_index >= 0) {
		// Get any objects on the layer.
		const CRhinoLayer &layer = layer_table[layer_index];
		ON_SimpleArray<CRhinoObject*> obj_list;
		int i, obj_count = pDoc->LookupObject(layer, obj_list);
		// Delete all of the layer's objects.
		CRhinoObject* obj; for (i = 0; i < obj_count; i++) { obj = obj_list[i]; pDoc->DeleteObject(obj); }
	}
	// Create a new layer.
	else {
		ON_Layer layer;
		layer.SetName(layer_name);
		layer.SetVisible(visible);
		if (wcslen(parent_name)) {
			int32_t parent_layer_index = layer_table.FindLayerFromUniqueName(parent_name, -1, -2);
			if (parent_layer_index > 0) {
				ON_Layer parent_layer = layer_table[parent_layer_index];
				layer.SetParentLayerId(parent_layer.Id());
			}
		}
		// Add the layer to the layer table.
		layer_index = layer_table.AddLayer(layer);
	}
	// If layer could not be added, layer index will be negative.
	return layer_index;
}

The key is to set the parent layer Id with this line:
layer.SetParentLayerId(parent_layer.Id());
before adding the layer to the layer table.

Regards,
Terry.