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

后端 未结 11 2213
-上瘾入骨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:20

    but this &(buffer[0]) looks ugly

    It’s the normal way. You can omit the parentheses, though:

    &buffer[0]
    

提交回复
热议问题