Deleting a reference

前端 未结 6 1487
情书的邮戳
情书的邮戳 2020-12-14 06:42

Is this valid? An acceptable practice?

typedef vector intArray;

intArray& createArray()
{
    intArray *arr = new intArray(10000, 0);

    r         


        
6条回答
  •  再見小時候
    2020-12-14 07:15

    It's valid... but I don't see why you'd ever want to do it. It's not exception safe, and std::vector is going to manage the memory for you anyway. Why new it?

    EDIT: If you are returning new'd memory from a function, you should return the pointer, lest users of your function's heads explode.

提交回复
热议问题