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.

  1. Include the necessary headers:
    #include <osg/ref_ptr>
    #include <osg/Referenced>
    #include <iostream>
  2. 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 ...

Get OpenSceneGraph 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.