In C++, if you pass an anonymous object as an argument to a named object method, does the anonymous object get deleted when you delete the named object?
The library I’m using for a project expects pointers to objects for most of its own objects’ methods, a la:
WContainerWidget::addWidget(WContainerWidget* widget) {/*...*/}
and in their examples they often use the new operator when constructing these objects.
WContainerWidget* aFoo = new WConainerWidget(/*args*/);
aFoo->addWidget(new WText(/*args*/));
If I delete aFoo, will the anonymous WText() object be deleted?
Am I to trust that their implementation will take care of these deletions without sorting through their source code, or should I avoid the exemplified behaviour, and explicitly name/delete everything myself?
Yes the widget takes ownership and it is automatically destroyed:
http://www.webtoolkit.eu/wt/doc/reference/html/overview.html
This is a badly defined interface. Its from the old school were people were still defining interface like C interfaces.
The passing of pointers is silly idea as there is no concept of ownership associated with it as such modern C++ libraries have shifted to using the concept of smart pointers. This provides a mechanism to document in the code (and enforce by the compiler) the concept of pointer ownership.