Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 19/05/2009 at 08:28, xxxxxxxx wrote:
User Information: Cinema 4D Version: 11 Platform: Windows ; Mac OSX ; Language(s) : C++ ;
--------- Hi,
i have a basic problem with my datatype. I have overwritten the "=" - operator and want to write something like this.
TestType a; TestType b = a; b //do something..
My problem is, that Cinema treats them like pointers. So if i change b, a will be changed to. The Cinema "default" =-operator does the same. I thought it could be the CopyData-function, but it's not called from Cinema in this case.
I hope you can help me.
Thanks,
Oli
On 19/05/2009 at 10:19, xxxxxxxx wrote:
How is the operator defined? Definition should look something like this:
> YourType& operator=(const YourType& src);
YourType& operator=(const YourType& src);
And the implementation should look like this then:
> YourType& YourType::operator =(const YourType& src) \> { \> //Do Something with YourType data \> return \*this; \> }
YourType& YourType::operator =(const YourType& src) \> { \> //Do Something with YourType data \> return \*this; \> }
On 20/05/2009 at 01:51, xxxxxxxx wrote:
So it is. Here the operator.
> AixGeometry& AixGeometry::operator=(const AixGeometry& src){ \> \> if(this == &src;){ \> \> return \*this; \> } \> \> //Allocate memory Points \> GeFree(this->pointArray); \> this->pointArray = NULL; \> this->pointArray = (AixPoint\* ) GeAlloc(sizeof(AixPoint) \* src.pointArraySize); \> \> this->pointArraySize = src.pointArraySize; \> \> //Allocate memory lines \> GeFree(this->lineArray); \> this->lineArray = NULL; \> this->lineArray = (AixNline\* ) GeAlloc(sizeof(AixNline) \* src.lineArraySize); \> \> this->lineArraySize = src.lineArraySize; \> \> //Allocate memory Ngons \> GeFree(this->ngonArray); \> this->ngonArray = NULL; \> this->ngonArray = (AixNgon\* ) GeAlloc(sizeof(AixNgon) \* src.ngonArraySize); \> \> this->ngonArraySize = src.ngonArraySize; \> \> //Points \> for(LONG i = 0; i < src.pointArraySize - 1; i++){ \> \> this->pointArray[i] = src.pointArray[i]; \> } \> \> //Lines \> for(LONG l = 0; l < src.lineArraySize - 1; l++){ \> \> this->lineArray[l] = src.lineArray[l]; \> } \> \> //Ngons \> for(LONG j = 0; j < src.ngonArraySize - 1; j++){ \> \> this->ngonArray[j] = src.ngonArray[j]; \> } \> \> //dirtyCount \> this->dirtyCount = src.dirtyCount; \> \> this->additionalAttributes = src.additionalAttributes; \> \> return \*this; \> }
AixGeometry& AixGeometry::operator=(const AixGeometry& src){ \> \> if(this == &src;){ \> \> return \*this; \> } \> \> //Allocate memory Points \> GeFree(this->pointArray); \> this->pointArray = NULL; \> this->pointArray = (AixPoint\* ) GeAlloc(sizeof(AixPoint) \* src.pointArraySize); \> \> this->pointArraySize = src.pointArraySize; \> \> //Allocate memory lines \> GeFree(this->lineArray); \> this->lineArray = NULL; \> this->lineArray = (AixNline\* ) GeAlloc(sizeof(AixNline) \* src.lineArraySize); \> \> this->lineArraySize = src.lineArraySize; \> \> //Allocate memory Ngons \> GeFree(this->ngonArray); \> this->ngonArray = NULL; \> this->ngonArray = (AixNgon\* ) GeAlloc(sizeof(AixNgon) \* src.ngonArraySize); \> \> this->ngonArraySize = src.ngonArraySize; \> \> //Points \> for(LONG i = 0; i < src.pointArraySize - 1; i++){ \> \> this->pointArray[i] = src.pointArray[i]; \> } \> \> //Lines \> for(LONG l = 0; l < src.lineArraySize - 1; l++){ \> \> this->lineArray[l] = src.lineArray[l]; \> } \> \> //Ngons \> for(LONG j = 0; j < src.ngonArraySize - 1; j++){ \> \> this->ngonArray[j] = src.ngonArray[j]; \> } \> \> //dirtyCount \> this->dirtyCount = src.dirtyCount; \> \> this->additionalAttributes = src.additionalAttributes; \> \> return \*this; \> }
But if i comment it out, Cinema builds its own =operator internally, which does the same garbage :-).
I have tried to write my DataType into GeData, copy the GeData into an other with its copy-function and read out the copied GeData. This doesn't work too.
On 20/05/2009 at 02:53, xxxxxxxx wrote:
Did you try to pass the reference as a = *b; ?
On 20/05/2009 at 03:46, xxxxxxxx wrote:
Ok this is funny. I have found a line in my code where i wrote something like this.
AixGeometry cubeCache = *defaultCube; //defaultCube is a pointer on an //AixGeometry
In this case it seems to work correct. But why it doesn't work if i have two "concrete" AixGeometries.
AixGeometry a; AixGeometry b;
b = a;
Is it not the same as b = *a if a is a pointer (AixGeometry* a)?
On 20/05/2009 at 07:48, xxxxxxxx wrote:
Ok, i found another line where a = *b doesn't work :-(. I have written a copy-constructor with the same success. It can't be mere chance, that the function one time does it's work and one time not.
I' m glad about every idea i get.
cheers,
On 20/05/2009 at 11:56, xxxxxxxx wrote:
Do you have a copy constructer defined in your AixGeometry class?
On 25/05/2009 at 01:56, xxxxxxxx wrote:
Hi,
yes, i have tried this too. But no chance; same garbage.
On 25/05/2009 at 02:46, xxxxxxxx wrote:
Actually the assignment operator must be called as a.operator=(b) is called in the case of a = b.
But if you have both defined (you should have both defined), an explicit copy constructor and an assignment operator, the only chance (cause I don´t know the structure of the full class you have there) you should in the end try a copy assignment operator, to avoid shallow copying.
On 26/05/2009 at 02:26, xxxxxxxx wrote:
So, i have tried this too; without success. I have also compared the memory-adresses - all correct. So i have to search anywhere else in my code.
Thanks for your help,
On 26/05/2009 at 02:30, xxxxxxxx wrote:
hmm, then I really have no other idea either. I am curious in knowing the solution to your problem if you find out.
Good luck
On 26/05/2009 at 06:16, xxxxxxxx wrote:
I got it :-). AixGeometry works like a container for the other datatypes (points, lines etc). In one of them i have commented out the operator= not so long ago to debug something.
So I summarise. To make deep copies of your datatype(s), you need the CopyData-function of each datatype, the operator= and the copyconstructor. If one of the last two functions doesn't exist, Cinema only makes a shallow copy.
So thanks for your help,
cheers Oli
On 26/05/2009 at 06:19, xxxxxxxx wrote:
ah there you go. Glad you finally worked it out. The good ol power of three.