field pointing to an object
BlitzMax Forums/BlitzMax Programming/field pointing to an object
| ||
Type Poo End Type Type Pee Field mypoo:Poo End Type local a:Poo=New Poo local b:Pee=New Pee local c:Pee=New Pee b.mypoo=a c.mypoo=a I guess this makes sense eh? b and c have a field which is kinda like an external field. Whenever I change a, b and c are automatically updated, since their Poo fields point to a. ('updated' is not the right word perhaps..) The question is if this can only be with done objects? I'd like the same thing for normal variables (as option).. bytes, ints, float etc. How to do that? |
| ||
Never use normal variables. Make a new type NInt with a field Int etc Then you can |
| ||
I figured that already, which is what I do already, but I was hoping it was possible without this 'hack' .. |
| ||
no it's not possible. Unless maybe you want to get into pointers but that's worse (less easy to understant) tan making a TInt type. |
| ||
@cs I dont think there is. I know I wanted to do this sort of thing and had a "flame" thread somewhere about it. And was told I was wrong so I should give up. I admit that I wanted this Type NInt extends IntWhich is different to what you are asking, But as the answer I was given was, "They (Types and internal objects), are not the same thing at all, they behave differently internaly and etc ..." It probably is the same for this. (But Hah, I know nothing) |
| ||
yeah I wanted to do the same for arrays. |
| ||
Well, this *does* work: Type TypeA Field value:Int End Type Type TypeB Field value:Int Ptr End Type a:TypeA = New TypeA b:TypeB = New TypeB b.value = Varptr(a.value) a.value = 5 Print b.value[0] |
| ||
We know. We've said it would (All you've done is extend the original example) |
| ||
if you wanted a variable 'a:int' and 'b:int' to both update when 'c:int' was changed then you would make 'a' and 'b' int pointers. Which applies to any primitive type. That's what you seem to be trying to get at..or I may be wrong. |
| ||
@Grey An array is an object so you should be able to have a (modifiable) array reference without a type wrapper. |
| ||
I wanted to extend an array type to add on some extra methods, but you can't do that. |
| ||
Ahh... stick... wrong end of... etc |
| ||
no worries, I didn't explain why I needed it :-) |