How to get the address of the std::vector buffer start most elegantly?

后端 未结 11 2215
-上瘾入骨i
-上瘾入骨i 2020-12-03 18:12

I want to use std::vector for dynamically allocating memory. The scenario is:

int neededLength = computeLength(); // some logic here

// this will allocate t         


        
11条回答
  •  执念已碎
    2020-12-03 18:27

    As already said, no.

    The reason is that &buffer[0] is the only way guarantied by the standard to get the adresse of the vector buffer.

提交回复
热议问题