New Method
BlitzMax Forums/BlitzMax Programming/New Method
| ||
I noticed the the following is allowed:Method New(iTest:Int) End Method So if it compile, why can't I invoke it? test = New Square(42) Thanks |
| ||
Hmm, aren't you meant to use methods within types? Is that the only code you have, or have you got more to show us? It's hard to analyze anything with such little code. |
| ||
I didn't bother putting the type. Asssume it is within type square. New is a special operator and I don't think you can invoke it using a parameter. At least not the normal way. |
| ||
Ahh, I see what you mean. My appologies Sean :o) Sorry, I don't have the answer to this one. |
| ||
I didn't know that would compile. New isn't supposed to have arguments so I'm guessing the parser just doesn't check for that. |
| ||
Funny thing is that if you change new to a function, it will tell you it must be a method? |
| ||
Funny thing is that if you change new to a function, it will tell you it must be a method? Thats because the method "NEW" exists as a method of the base object, (This may not be correct, cos intuitivly you would think it would be a function) What you are doing is creating a method that is called after the base "New" SuperStrict Type MyType Field MyField:Int Method New:MyType() MyField=10 Print "Hello" End Method EndType Local Variable:MyType = New MyType Print Variable.MyFieldI am very supprised to hear that it excepts parameters, cos I dont think it should. You do this, when you want to add each instance to a list or such, or you need a more dynamic creation. (Well realy I dont think you should ever do it, and think MyType.Create:MyType(Params) is better) |
| ||
perhaps im mistaken - but i thought bmax methods in user defined classes override the same methods in parent classes? - surely this means that the base method is not called..as this wouldnt be desired in most cases. [new() may well be an exception to the rule..] Its stated in the docs that the overriden methods must have the same signature!..so the param list must surely have to match up correctly?..hmmm, perhaps theres an issue with methods that take no params.. anyway - new() is not supposed to accept params, bmax does not support overloaded methods..perhaps this will come in the future, but its probably been left out to keep things simple. |
| ||
All New methods in a chain of inherited types are called starting with Object and finishing with the New method that was originally called. |
| ||
thats how i expected it would work..lol, sorry if i confused anyone..jst wasnt sure how this stuff worked under bmax.. havent used it for a while..atleast not in an oopy way.. thanks for clearing that up cajun17 - i tried a simple test in bmax to confirm it....wasnt sure if parents new() method had to be called explicitly, which would have been a pain... anyway, good know. |
| ||
so you don't have to do Super.New() weird, but OK. |
| ||
so, is the NEW method is a defacto constructor then? --Mike |
| ||
Indeed it is. As will the following be the standard Destructor. Method Delete() End Method |