I have the following problem. Let’s assume you have a class TObject which is Super of some classes as TDouble, TInteger, etc…
I want to implement a virtual method Value() in TObject to be overwritten in the derived classes. The problem is that in TDouble
I want to return a double, in TInteger I want to return an integer, etc…
[quote=329459:@Eli Ott]You cannot overload a method which returns a value.
You would need two different parameter lists to be able to overload.[/quote]
I think what you mean is you cannot overload SOLEY on return type
This would not work
function test(x as integer) as integer
function test(x as integer) as double
function test(x as integer) as string
a valid overload requires the values between the ( ) to be different datatypes (and can be a different number of arguments), if there is a return value they must all be the same… with one exception… when you are emulateing a computed property. A normal CP cannot accept arguments, but it is possible to create a function and method with the same name to achieve the same result
FUNCTION test(x as integer,y as integer) as integer // this would be the equivalent of GET
SUB test(x as integer,y as integer,assigns newvalue as integer) // this would be the same as SET
thank you guys for all the inputs. @Eli Ott Thank you for the code, I will take a look at it.
I was thinking that another approach could be to make mValue an instance of TObject itself.
In that case for example TDouble would return TDouble (which is possible since derived from TObject).
Does it make sense to you?