Question

How can I tell if a pointer is an RValue or I don't know what I'm talking about.. This really ridiculous idea popped into my head while drinking a beer..

What if you have stupid programmer/user..

Assume you have the following class:

template<typename T>
class Container
{
    private:
        std::vector<T> Storage;
    public:
        Container(T Anything) : Storage() {Storage.push_back(Anything);}
}

and the user does:

Container<Object*> C(new Object(Params));

Then how can I delete it? I want to be able to tell the difference between the above and the below:

Object* O = new Object(Params);
Container<Object*> C(O);

I just want to know. I know that the first example obviously should not be used but let's assume that it will be or that I want to detect leaking code like that and delete them.

How can this be done? Is that an RValue pointer? What do I call that?

Was it helpful?

Solution

Easiest and correct thing would be to wrap naked pointers in some resource container like shared_ptr.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top