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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -