title: Initializing a public char buffer dynamically
body: <p>I am a noob to C++. I have a question regarding initialization of a character buffer dynamically</p>
  
  <pre><code>class Pkg {
    public:
      Header t;
      char buf[LENGTH];
  };
  </code></pre>
  
  <p>I am going to send the object of the class over the network.
  Header class is converted to network byte order</p>
  
  <p>So, I want to send it like this</p>
  
  <pre><code>Pkg ackpkt;
  
  sendto(sd, &amp;ackpkt, sizeof(ackpkt), 0,(struct sockaddr*)socket1,sizeof(struct sockaddr_in);
  </code></pre>
  
  <p>The LENGTH field here should be dynamically assigned each time just before I call sendto.
  One way I think of doing this is by declaring LENGTH to be global.</p>
  
  <p>At the receivers side, I want to receive the object in an object of the same class.i.e the data of object t should be organized in ackpktrecv.t and buffer in ackpktrecv.buf</p>
  
  <p>recvfrom(sd, &amp;ackpktrecv, sizeof ackpktrecv, 0, (struct sockaddr*)&amp;sockaddrs, &amp;len);</p>
  
  <p>How can I receive the object with the character buffer having the same length as LENGTH
  Can anybody suggest me in what way I can achieve this ?</p>