c++ - Initialize a vector inside a struct -
i have following struct:
struct msgproperties { dword msgsize; std::vector<byte> vbuffer; //-constructor msgproperties(dword = 0) : msgsize(a){} };
i want use struct c++ vector i've done:
std::vector<msgproperties> readtext; byte buffer[max_buffer_size]; dword bytesread; { bytesread = myfile.read(buffer, max_buffer_size); readtext.push_back(msgproperties(bytesread, std::vector<byte>((byte*)buffer, (byte*)buffer + bytesread))); } while (bytesread > 0);
but can't figure out how make work correctly. can tell me missing?
looks need 2 constructors:
msgproperties(dword a, const std::vector<byte>& vec) : msgsize(a), vbuffer(vec) {} msgproperties(dword a, std::vector<byte>&& vec) : msgsize(a), vbuffer(vec) {}
alernatively, single constructor too:
msgproperties(dword a, std::vector<byte> vec) : msgsize(a), vbuffer(std::move(vec)) {}
on side note, not see why need message size @ all. size of vector message size.
Comments
Post a Comment