> >> It doesn't hurt to have the cleanup code in the destructor *also*,
> >> but it shouldn't be the only place IMO. One may choose to manage
> >> the lifetime of the "socket" resource explicitly in C++.
> >
> > Yes, that makes sense.
>
> C++ invokes destructors automatically and immediately. If you want to
> avoid strict scoping for the object you can allocate it dynamically:
>
> {
> ctx = new zmq::context_t (1, 1);
> ...
> if (...)
> delete ctx; // destructor is called here
> ...
> } // instead of here
>
> I prefer it this way as it doesn't require handling brain-dead
objects.
I think the point is to have an explicit function to destroy the object,
and ALSO call that same function from the destructor. So in C++ you
would do:
class Foo {
public:
Foo() { /* blah */ }
~Foo {destroy(); }
void destroy() { /* blah */ }
};
This way you can call destroy() whenever you want, and it will be called
for you automatically when the object's destructor is called.
--
Gonzalo Diethelm
-----------------------------------------
Declaración de confidencialidad: Este Mensaje esta destinado para
el uso de la o las personas o entidades a quien ha sido dirigido y
puede contener información reservada y confidencial que no puede
ser divulgada, difundida, ni aprovechada en forma alguna. El uso no
autorizado de la información contenida en este correo podrá ser
sancionado de conformidad con la ley chilena.
Si usted ha recibido este correo electrónico por error, le pedimos
eliminarlo junto con los archivos adjuntos y avisar inmediatamente
al remitente, respondiendo este mensaje.
"Before printing this e-mail think if is really necesary".
Disclosure: This Message is to be used by the individual,
individuals or entities that it is addressed to and may include
private and confidential information that may not be disclosed,
made public nor used in any way at all. Unauthorized use of the
information in this electronic mail message may be subject to the
penalties set forth by Chilean law.
If you have received this electronic mail message in error, we ask
you to destroy the message and its attached file(s) and to
immediately notify the sender by answering this message.
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev