Skip to content

[Question] Is there a way to call delegating constructor? #409

Closed
@thedmd

Description

@thedmd

I'm plaing with cppfront trying to port some bits of code to get a feel of new syntax.

One thing I cannot figure out is how to write operator=: to delegate construction.
I tried operator=: (out this, major: u32) = this(major, 0, 0, 0);, operator=: (out this, major: u32) = this := (major, 0, 0, 0);, even stared with operator=: (out this, major: u32) = Version(major, 0, 0, 0);.

In cppfront source I didn't found code emitting, but I'm not yet 100% sure.

Did I missed the intended syntax or feature is not present at this time? Thanks!

For reference:

Version: @value type =
{
    Major:      u32 = 0;
    Minor:      u32 = 0;
    Revision:   u32 = 0;
    Patch:      u32 = 0;

    operator=: (out this, major: u32)                                        = { this.Major = major; }
    operator=: (out this, major: u32, minor: u32)                            = { this.Major = major; this.Minor = minor; }
    operator=: (out this, major: u32, minor: u32, revision: u32)             = { this.Major = major; this.Minor = minor; this.Revision = revision; }
    operator=: (out this, major: u32, minor: u32, revision: u32, patch: u32) =
    {
        this.Major    = major;
        this.Minor    = minor;
        this.Revision = revision;
        this.Patch    = patch;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions