I looked at zmq.hpp, and both socket_t and context_t require
parameters at construction.
context_t requires threads
socket_t requires context and type
if you need to defer construction, and you want to use the standard
zmq.hpp interface, you'll need to use pointers, or create an object
within your object which has the proper initialization.
Alternatively, you can pass references into your class:
class foo {
zmq::socket_t& socket_;
public:
foo(zmq::socket_t& socket) : socket_(socket) { }
...
The no_throw version of the library I built has an "init" call for
each class, allowing for a default constructor "BUT" it doesn't throw
of course.
There might be a need for an intermediate form of the library, which
has default constructors, can have an uninitialized state, and throws.
Then you could write:
class foo {
zmq::init::socket_t socket_;
public:
void weeks_later() {
...
socket_.init(some_context, ZMQ_WHATEVER);
...
}
If you referenced the "uninitialized" socket, the class would know
this and throw an exception(uninitialized).
Try looking at git://github.com/mjw9100/zmq_nothrow.git
Best,
Matt
On Sep 24, 2010, at 11:30 AM, Douglas Creager wrote:
>> Anyone manage to use context and socket as C++ object members without
>> getting "syntax error: constant" and without using pointers?
>
> Do you have a code snippet of what you're trying to do?
>
> Both context_t and socket_t are missing copy constructors and
> assignment
> operators, so you'd have to create new instances in your own
> constructor
> using an initialization list. You couldn't take them in as a
> parameter
> from somewhere else.
>
> If you need to take in a context from somewhere else, and don't want
> to
> use a pointer, I'd try a reference or a shared_ptr.
>
> –doug
>
> _______________________________________________
> zeromq-dev mailing list
> [email protected]
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev