How to directly transfer an array to a function in c ++ 11 ? For the example of java, it would look like this:
void arraySetter(float[] array) { this.array = array; } arraySetter(new float[] {1.2, 2.53, 6.23}); In c ++, I do something similar in one of the classes, let it be SomeClass :
void SetArray(float array[]) { this->array = array; //error: incompatible types in assignment of 'float*' to 'float [0]' } And I call (most likely not correctly):
some_class_pointer->SetArray(new float[5]{2.4, 1, 0.76, 0.54, 0.33})
C, unlikeJava, you don’t know the size of an array. Therefore, it makes sense to think about what is necessary. And yes, how did you declarearrayin the class? if as afloat *it is compiled and if as afloat[]then this in itself is not very correct and means something else. - pavelsizeof(array)/sizeof(array[0])? - Herrgotttype[]converted totype *(you can check). - pavel