FreeBASIC syntax challenge games

For other topics related to the FreeBASIC project or its community.
fxm
Posts: 7894
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: FreeBASIC syntax challenge games

Postby fxm » Oct 30, 2017 15:20

fxm wrote:Pseudo-code for the particular solution (function returning a reference to the instance on which it was called):
    Cast(Base_Type, derived_instance) = Base_Type(derived.instance).overridden_function()

Maybe this line of code equivalent to the one above, but formalized with a slightly different syntax, will speak to you more:
    Cast(Base_Type, derived_instance) = Type<Base_Type>(derived.instance).overridden_function()
The idea is to create a temporary copy of the derived instance, and to call the function on it.
=> one single code line.

[edit]
Posting the adding in a new post.
Last edited by fxm on Oct 31, 2017 13:46, edited 2 times in total.
dodicat
Posts: 4824
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: FreeBASIC syntax challenge games

Postby dodicat » Oct 31, 2017 13:39

You have more or less given the solution.
Cast(parent,c) = Type<parent>(c).dec

Which I checked on -gen gcc.

Grindstone solved the previous one well, and sancho2 contributed a while back with a solution for another.
I don't mind having a try now and then, although I am not very good.
But failing miserably is no problem for me.
fxm
Posts: 7894
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: FreeBASIC syntax challenge games

Postby fxm » Oct 31, 2017 13:47

When a Type directly or indirectly derives from the built-in type Object, compiler adds an implicit default-constructor and implicit copy-constructor to the Type whatever its own fields or inherited fields.
(both 'Base_Type(derived.instance)' and 'Type<Base_Type>(derived.instance)' calling the copy-constructor to create a temporary copy)
Last edited by fxm on Oct 31, 2017 20:49, edited 2 times in total.
fxm
Posts: 7894
Joined: Apr 22, 2009 12:46
Location: Paris suburb, FRANCE

Re: FreeBASIC syntax challenge games

Postby fxm » Oct 31, 2017 14:08

dodicat wrote:Grindstone solved the previous one well, and sancho2 contributed a while back with a solution for another.
I don't mind having a try now and then, although I am not very good.
But failing miserably is no problem for me.

The most important is not the solution in itself, but especially all the paths taken to try to get there.

Return to “Community Discussion”

Who is online

Users browsing this forum: Eddie and 1 guest