Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17075

How to inherit from Ref properly?

$
0
0

@Greenhouse wrote:

What is the common pattern to derive from Ref without leaks?

Is the following snippet safe?

class Derived : public cocos2d::Ref
{
public:
    Derived () : x(0), y(0), z(nullptr) {}

    size_t                          x;    
    size_t                          y;  
    cocos2d::Sprite*                z;
};

Should I add destructor to Derived as well:

~Derived () 
{
    if (this->getReferenceCount() > 0)
        this->release();
}

Posts: 5

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17075

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>