what does "layout-compatible with C" mean?
It is said that stl vector is "layout-compatible with C". Where can I find the definition 开发者_高级运维of "layout-compatible with C"?
This means that, as long as the vector is not empty, &vector.front()
will give you a pointer to a contiguous array of objects, which could be passed to a C API that expects such an array.
It means that the contents of the vector will be laid out in memory the same way they would be in a C array of the same type. That means that if you have a C function that expects to receive a pointer to an array of some type, you can use a vector and pass the function a pointer to the first element of the vector.
精彩评论