Referencing New (Constructor)

About Monkey 2 Forums Monkey 2 Programming Help Referencing New (Constructor)

This topic contains 4 replies, has 3 voices, and was last updated by  Matthew Smith 2 years, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #1215

    Matthew Smith

    I’m wanting to essentially overload New but rather than having to duplicate code, I’d like to pass onto another New like such:

    As you can see the first New is calling the second New.  Currently I’m getting the following:

    Been quite a while since I did any Blitz/Monkey coding so a bit rough in remembering this stuff! Too much C# nowadays. Thanks Playniax for the example.



    In Java you can do something like this(pun!) with ctor chaining:


    With Monkey I think you need to create a common method or function:


    It would be nice to have ctor chaining.


    Matthew Smith


    Thanks for your response – yeah would be a nice to have! But no probs.

    C# has a similar option using both this (Self) and base (Super):


    Mark Sibly

    Unfortunately, you’ll currently have to use the ‘Init’ approach for this particular code.

    The problem is that you can’t currently have ‘complex’ parameter expressions when you chain new’s together (ie: the ‘New Image[]( image )’ ) – mainly because you can’t in C++, and mx2 New currently maps directly to c++ ctors. Which seemed like a good idea at the time but has proven to have some serious limitations.

    I do plan to eventually fix this though, hopefully soon!


    Matthew Smith

    Ok – thanks Mark!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.