Returning Array from Object using Accessor in C++ -
I'm new to C ++ and trying to know myself C ++ I write the code for my project , But I have to face difficulties in returning an array from class accessor.
I have a class called loaddown that accepts array_a [] Load data class constructor copies memory block of array_a to an array, an accelerator, GetArray () attempting to return a pointer in the arrayA
In the main (), I create an array of objects, objVec [obj_i], which collect data and collections in the class. When I try to return an array from LoadData and print the content, I get only the first element of the right element and return the rest of the memory address.
I believe that the problem I am doing is either the way I am returning an array in the accelerator or the way I am calling getArray () I use the pointers There is a lot of trouble.
I am struggling about this for about a week so that any suggestions and input will be appreciated! Thank you very much in advance.
class load data {private: float * array; Public: // Constructor LoadData (Flat Array_a []) // Accelerated Float GetArray () {Return * arrayA}}; LoadData :: LoadData (float array_a []) {arrayA = new float [shape offray] mempi (array, array_a, size (int) * sizeofferre); } Int main () {class LoadData; Int objSize = 6; LoadData ** objVec = New LoadData * [objSize]; Obj_i = 0; // Loop to load data (...) {objVec [obj_i] = new load data (array_a)} float * copy array; * CopyArray = objVec [1] - & gt; GetArray (); For (Int i = 0; I & lt; Size OFFER; I ++) {COAT & LT; & Lt; * (Copyre + I) & lt; & Lt; '\ T'; } // sign}
Float getArray () {return * arrayA;}
Say that you are returning float
, and you are.
If you want to return the pointer (which is not the same thing as an array):
float * getArray ( ) {Return array A; }
Comments
Post a Comment