www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17655] New: Call parent class reference.

https://issues.dlang.org/show_bug.cgi?id=17655

          Issue ID: 17655
           Summary: Call parent class reference.
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: vital.fadeev gmail.com

Created attachment 1651
  --> https://issues.dlang.org/attachment.cgi?id=1651&action=edit
source code

Exxample:
    class Node {
        Node[] members;
        Node parent;

        void add_member(ref Node member) {
            members ~= member;
            member.parent = this;
        }
    }

    class Char : Node {
    }

    class Image : Node {
    }

    Node root = new Char();
    Char ch = new Char();
    Image image = new Image();

    root.add_member(ch);
    root.add_member(ch);
    root.add_member(ch);
    root.add_member(image);
    root.add_member(image);
    root.add_member(image);

This is simple tree implementation:
Node
  Char
  Char
  Char
  Image
  Image
  Image


dmd compile it with error: 
Error: function Node.add_member (ref Node member) is not callable using
argument types (Char)

I try casting, but also error:
    root.add_member(cast(Node)ch);

I try pass by out and inout, but also error:
    void add_member(out Node member) {...}
    void add_member(inout Node member) {...}

What is true way?

I need change the property "parent" (Node.parent = this) and I think what pass
by reference is good (ref Node member). Or not?

--
Jul 15 2017