Copy A.MyType to B.MyType
Blitz3D Forums/Blitz3D Programming/Copy A.MyType to B.MyType
| ||
I couldnt find something for that in the manual, how do i copy an object? For instance, i want my object A.MyType be the same as B.MyType. I could think of two methods, but also they seem to work in general, at some points something seems wrong. I wonder wether it is "allowed" what im doing or there is something wrong elsewhere. 1) A=B.MyType 2) MyHandle=Handle(B.MyType) A=Object.MyType(MyHandle) Thanks for your help. |
| ||
It's not that simple. You're making A and B point to the same object. what you need to do is make A and B different objects containing similar information. You will need to do: A.mytype=new mytype A.Field1=B.Field1 A.Field2=B.Field2 A.Field3=B.Field3 A.Field4=B.Field4 A.Field5=B.Field5 A.Field6=B.Field6 A.Field7=B.Field7 |
| ||
Ok, i understand why what i was doing isnt working. But i wonder if there is a quicker method than A.Field1=B.Field1 A.Field2=B.Field2 A.Field3=B.Field3 .... ? |
| ||
Nope, I'm afraid not. I wish there was a "CopyOf" function.A.Mytype=CopyOf B.Mytype Unless anyone else knows any cunning methods? |
| ||
when you say 'quicker method' do you mean quicker to program or quicker on runtime? if it's the former: ((Hope this helps, Ive not tried it or anything, just wrote it here in browser window!)) |
| ||
C++ provides default copy constructors for "plain old data" (POD) structures. There's no functionality like this in Blitz. If you're not concerned about performance, you could use Hash Tables, which can be copied programmatically. |
| ||
With "quicker method", i ment easier to programm, especially easier to make changes. I like to change most things a little over time, with this method i would have a lot of work if i, for example, add another integer to the type or whatever. Of course performance is also an issue. Well, thanks for your help. |