Initialize a float array on construction

前端 未结 2 1079
悲&欢浪女
悲&欢浪女 2021-02-20 09:34

Is there a way in C++ to construct a float array initializing it\'s values?

For example, i do:

float* new_arr = new float[dimension];
for(unsigned int i          


        
相关标签:
2条回答
  • 2021-02-20 10:04

    In this particular case (all zeroes) you can use value initialization:

    float* new_arr = new float[dimension]();
    

    Instead of explicitly using new[] you could use a std::vector<float> instead:

    std::vector<float> new_vec(dimension, 0);
    
    0 讨论(0)
  • 2021-02-20 10:04
    float* new_arr = new float[dimension]();
    
    0 讨论(0)
提交回复
热议问题