www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3790] New: [OOP] constructor of child class cannot pass arguments into parent constructor

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3790

           Summary: [OOP] constructor of child class cannot pass arguments
                    into parent constructor
           Product: D
           Version: 2.041
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: denis.tomilin gmail.com



Constructor of child class cannot pass arguments into parent constructor.
See the example:

class A{
 final this(int a=0){
  writeln(a);
 }
}
class B:A{
}

B b = new B(); //prints 0
B b2 = new B(2); //throws an error "expected 0 arguments, not 1..."

As we can see, logic is normal, but not in dmd. This bug creates a new bug:

class A{
 final this(int a=0){
  writeln(a);
 }
}
class B:A{
 this(int a=0){ //compiler perfectly, but parent constructor marked as "final"
  super(a);
 }
}

It might be not a hard problem, but it will be good for my project to create a
logical, nice-look code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 09 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3790




Also, if we dont give argument a default value, we get an error:
Error: constructor main.B.this no match for implicit super() call in
constructor
As i think, somebody thinks in different way with a lot of stones and problems
=/

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3790


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
           Severity|blocker                     |enhancement



This bug report has two issues:
(1) an enhancement request: allow constructors to be inherited.
and
(2) an accepts-invalid bug: 'final this()' is accepted, even though this() is
_always_ final.

Downgrading to enhancement.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 12 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3790


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86_64                      |x86



---
Mass migration of bugs marked as x86-64 to just x86.  The platform run on isn't
what's relevant, it's if the app is a 32 or 64 bit app.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011