oups beter like this, or with any other smart pointer

MyClass & getInstance()
{
    static osg::ref_ptr<MyClass> myClass( new MyClass() );
    return *myClass;
}



2013/4/26 David Callu <led...@gmail.com>

> Hi Sajjadul,
>
> There are nothing in OSG to do this, but make a class a singleton is
> really straightforward.
>
> - make constructor protected or private,
> - add a static getInstance function
>
> MyClass & getInstance()
> {
>     static MyClass * myClass = new MyClass();
>     return *myClass;
> }
>
> then use it in your code
>
> MyClass::getInstance().doStuff();
>
> alternatively, you can google 'boost+singleton' to see some examples of
> implementation
>
> HTH
> David
>
>
>
> 2013/4/26 Sajjadul Islam <dosto.wa...@gmail.com>
>
>> Hello forum,
>>
>> I have a class declaration and i want to create a singleton instance to
>> it.
>>
>> Is there any utility class inside OSG that enables something like this?
>>
>> Thank you!
>>
>> Cheers,
>> Sajjadul
>>
>> ------------------
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=53820#53820
>>
>>
>>
>>
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to