Modifying BaseArray inside a function

  • On 05/06/2018 at 22:15, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   14+ 
    Language(s) :     C++  ;


    I want to modify a BaseArray inside a function and return it. If I try to return the same BaseArray I get an error that it is inaccessible. 
    For example (pseudo code) :

    // Define the BaseArray
    maxon::BaseArray<Float> myFloats;
    // Use the BaseArray in a function
    maxon::BaseArray<Float> myFunction(&myFloats)
    	for (Int32 i=0; i<myFloats.GetCount(); i++)
    		myFloats[i] = i;
    	return myFloats;   // --------> this does not work

    Any ideas?

  • On 06/06/2018 at 01:33, xxxxxxxx wrote:

    Hi Salozo,

    First of all the code, you show us is a bit weird.
    If you only want to modify the BaseArray, since you pass a reference you just have to modify it without the need to return it.
    Actually, the error comes from the fact that you are returning a new BaseArray. So you copy the existing BaseArray. And BasseArray doesn't have a Copy Constructor.

    But if you really want to have a new BaseArray, you have to create a new BaseArray, then use newArray.CopyFrom(myFloats)
    and finally, return a reference/pointer to this array.


Log in to reply