Creation and destruction responsibilities

M

Miguel Guedes

I'd like some clarification on the correct way to destroy an object.

I've seen a couple of open source projects make use of object factories to
instantiate classes and smart pointers to destroy them when the ref_count
reaches zero. Something like:


pInstance = Factory::createSomething();

{
smart_ptr<Something> ptr = pInstance
.
:
}

// out of scope: smart_ptr destroys pInstance


My question is, isn't a creator entity supposed to be responsible for the
destruction of the objects it creates? Isn't this one of the golden rules of
correct OO code design and what RAII is all about?

Would appreciate some clarification on this. Thank you.
 
W

Walter Roberson

I'd like some clarification on the correct way to destroy an object.

The code you gave appears to be C++ . I would suggest asking in
comp.lang.c++ .
 
M

Miguel Guedes

Walter said:
The code you gave appears to be C++ . I would suggest asking in
comp.lang.c++ .

Yes, I'm sorry. Only now did I realize the mistake I made.

Again, I apologise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top