x=New x error
BlitzMax Forums/BlitzMax Programming/x=New x error I think bat being null when you do it is the problem. New, when passed an object instead of a type name, will create a new object of the same type as that object, but if that object is null it shouldn't work.
What's weird about that?
on the first sample
new only accepts types. it does the same as "new" in c like languages: it creates a new instance of the class / type you tell it.
There is no type "i" ( as well as "int" etc are no types that can be instanced )
and the second sample:
new requires, as mentioned above, the TYPE, not a variable ( see the helpfiles on userdefined types for further informations )
new only accepts types. it does the same as "new" in c like languages: it creates a new instance of the class / type you tell it.
There is no type "i" ( as well as "int" etc are no types that can be instanced )
and the second sample:
new requires, as mentioned above, the TYPE, not a variable ( see the helpfiles on userdefined types for further informations )
On the "bob=New joe" sample, the compiler should be puking because "joe" isn't a type. Looks like a compiler bug...
and the second sample:
new requires, as mentioned above, the TYPE, not a variable ( see the helpfiles on userdefined types for further informations )
my code works on the second example.
Damn, I wrote a test program and was thinking, hmm, maybe Mark made that a way to do copy construction, but no. How about that Mark?
Aaron
Aaron
heh ya, that would explain why it works only when joe is not null, (in bob:person=new joe)
But it should be fixed that it gives a windows program crash (in a similar situation) with debug ON. that shouldnt ever happen with debug on.
But it should be fixed that it gives a windows program crash (in a similar situation) with debug ON. that shouldnt ever happen with debug on.
As I said,
It's a documentation issue.
The feature is so you can do something like this - which *doesn't* work, because SizeOf is incorrectly returning 0:
New, when passed an object instead of a type name, will create a new object of the same type as that object
It's a documentation issue.
The feature is so you can do something like this - which *doesn't* work, because SizeOf is incorrectly returning 0:
Type CloneableObject Method Clone:Object( ) Local sel:Object = Self Local obj:Object = New sel MemCopy( Byte Ptr( Varptr( obj ) ), Byte Ptr( Varptr( sel ) ), SizeOf( sel ) ) Return obj End Method End Type Type Enemy Extends CloneableObject Field x#, y# End Type Local BadGuy:Enemy = New Enemy BadGuy.x = 50 BadGuy.y = 60 Local AnotherBadGuy:Enemy = Enemy( BadGuy.Clone( ) ) RuntimeError AnotherBadGuy.x + "," + AnotherBadGuy.y