Jump to content
  • Advertisement
Sign in to follow this  
StormbringerCSP

Class instantiation as non-pointer

This topic is 4843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i'm trying to master the OpenSceneGraph (OSG) lib, but i already fail right at the beginning. I just want to get an instance of a class:
osg::PositionAttitudeTransform instPosAttitudeTrans;
The compiler replies with
error C2248: 'osg::PositionAttitudeTransform::~PositionAttitudeTransform' :
   cannot access protected member declared in class 'osg::PositionAttitudeTransform'
d:\CSP\usr\include\osg\PositionAttitudeTransform(68) :
   see declaration of 'osg::PositionAttitudeTransform::~PositionAttitudeTransform'
d:\CSP\usr\include\osg\PositionAttitudeTransform(28) :
   see declaration of 'osg::PositionAttitudeTransform'
That's how the class is defined in the header:
class SG_EXPORT PositionAttitudeTransform : public Transform
{
    public :
        PositionAttitudeTransform();
        ...

    protected :
        virtual ~PositionAttitudeTransform() {}
Instantiating a pointer instead works:
osg::PositionAttitudeTransform* posAttitudeTransform2
		= new osg::PositionAttitudeTransform();
Why am i not allowed to instatiate a single instance, but only a pointer? For my understanding, "osg::PositionAttitudeTransform instPosAttitudeTrans;" should call the default constructor. What's wrong here? Thanx, Stormbringer
[edit by kSquared: broke up excessively long code lines]

Share this post


Link to post
Share on other sites
Advertisement
Try deleting the pointer, you'll probably get the same kind of error message. When you allocate a weapon in automatic storage, you implicitly generate the code to destroy the object. This will generate an error if you try to instantiate an object with a private or protected destructor. You won't get the same message right a way with new, it comes later when you try to delete.

Share this post


Link to post
Share on other sites
Thanks! Someone just told me that OSG uses reference counting for its objects. So making the destructor protected prevents object creation on the stack. This type of array building should work:
std::vector<osg::ref_ptr<osg::PositionAttitudeTransform> > arrayPAT(4);
for (int i = 0; i < 4; ++i) arrayPAT = new osg::PositionAttitudeTransform;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!