Hello again for the second time in under 12 hours!
So this has been bothering me for a while, how do you pass an actual type (not an instance of the type) to a function?
For example, I want to do this:
However I simply get told "Compile Error: Expecting identifier but encountered Type". This leads me to think that maybe the solution lies in pointers.
There are other things this would be useful for, for instance functions which can create generic objects depending on which object is passed, etc.
I do kind of have a solution in mind for if this isn't possible, that is to assign each type a Const ID thing, and just check for that. However that would be a lot clumsier, and I'd prefer not to have to.
So this has been bothering me for a while, how do you pass an actual type (not an instance of the type) to a function?
For example, I want to do this:
Type TBall Method New() Objects.Addlast(self) EndMethod EndType Type TDrWatson Method New() Objects.Addlast(self) EndMethod EndType Function ObjectCount:Int(Obj:Type) Local num:Int For Local o:Obj = EachIn Objects num:+1 Next Return num End Function Global Objects:TList=new TList new TBall new TBall new TDrWatson print ObjectCount(TBall) print ObjectCount(TDrWatson)
However I simply get told "Compile Error: Expecting identifier but encountered Type". This leads me to think that maybe the solution lies in pointers.
There are other things this would be useful for, for instance functions which can create generic objects depending on which object is passed, etc.
I do kind of have a solution in mind for if this isn't possible, that is to assign each type a Const ID thing, and just check for that. However that would be a lot clumsier, and I'd prefer not to have to.