Time for action—monitoring counted objects
We will first declare a customized class that is derived from osg::Referenced
. This can benefit from the garbage collecting system by using the smart pointer. After that, let's take a look at the initialization and cleanup procedures of our referenced objects.
- Include the necessary headers:
#include <osg/ref_ptr> #include <osg/Referenced> #include <iostream>
- Define the customized
MonitoringTarget
class with a unique name,_id
. We will simply use the standard output to print out verbose information when constructing and destructing:class MonitoringTarget : public osg::Referenced { public: MonitoringTarget( int id ) : _id(id) { std::cout << "Constructing target " << _id << std::endl; } protected: virtual ~MonitoringTarget() ...
Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.