[zeromq-dev] C++ syntax for new ZMQ objects

Claudio Carbone erupter at libero.it
Fri Dec 14 19:15:14 CET 2012


Hello all.

I'm surely a noob in C++, so I am having difficulties managing ZMQ in 
this language.

I'm creating a class that will include both a client and a server so I 
have this structure

namespace Saetta
{
     class Server
     {
         public:
             Server(void);
             virtual ~Server();
             void worker();




         private:
             std::string _base_ip_address;
             int _client_list[];
             int _counter;
             char _count[3];
             zmq::context_t _zmq_context;
             zmq::socket_t _zmq_socket;
     };

     class Client
     {
         public:
             Client(void);
             virtual ~Client();
             void worker();

         private:
             zmq::context_t _zmq_context;
             zmq::socket_t _zmq_socket;
     };
}

I have to convert the basic
     zmq::context_t context(1);
     zmq::socket_t publisher(context, ZMQ_PUB);
     publisher.bind("tcp://*:5555");
into something feasible for my class.

So I thought writing this into the constructor
this->_zmq_context = new zmq::context_t(1);
this->_zmq_socket = new zmq::socket_t(this->_zmq_context, ZMQ_PUB);
this->_zmq_socket.bind("tcp://*:5555");

None of this works.

Hope there is somebody kind enough to explain to me how should I phrase 
the declarations to have them work with ZMQ.

Thank you
Claudio



More information about the zeromq-dev mailing list