Socket read()ing into a function that returns pointer in C++ -
I have a class named
class messages {private: header type header; // message text byte * text; Public: ~ Message (); Byte * getText (); ...}; / * * Destructor * / Message: ~ Message () {if (header.ack == false) Free (text); } / * * GetText * * pointer to the text * / byte * message: getText () {return text; } I will read directly in text , therefore, I have created the above function Message :: getText () which gives the text an indication is. Again, I read in this ceremony. I know, this is wrong, would anyone tell me why?
Read (receive_socket, m.getText (), header.dataSize);
Who is responsible for maintaining that data? I should have a free (which should be removed from ) [/]> ) but I do not see a new anywhere Just returning a raw indicator?
This is a good use case for vector
class messages {private: header type header; // message text std :: vector & lt; Char & gt; Text; }; Std :: vector & lt; Four & gt; & Amp; Message: getText () {return text; } Which would be a little better if you fit into your socket descriptor in your message then it can read your:
int reading (int sd) {text.resize (header.dataSize); Return: Read (SD, & Text [0], header.dataSize); }
Comments
Post a Comment