3 Replies Latest reply on Nov 24, 2013 5:37 PM by huangxinghui

    What is wrong with you mr Compiler (mxmlc) ?

    ScreenMan

      here is SIMPLE code I tried to compile:

       

      CODE:>>>>>>>>>>>>>>>

      package {

       

        public class Test {}

      }

       

      class Foo {

        // paramBelow is the source of a compiler error

        public function Foo(paramBelow:int) {

        }

      }

       

      class Bar extends Foo {}

      <<<<<<<<<<<<<<<<<<<<<

       

      When i'm simply trying to compile that code with mxmlc I get following error:

       

      col: 1 Error: No default constructor found in base class Test.as$1:Foo.

       

      package {

      ^

       

      Is that a compiler bug, or something I do wrong ?

        • 1. Re: What is wrong with you mr Compiler (mxmlc) ?
          huangxinghui Level 1

          class Bar inherit from class Foo, and class Foo's constructor is "public function Foo(paramBelow:int) {}", so class Bar's constructor should be defined like this "public function Bar (paramBelow:int) {super(paramBelow)}"

          • 2. Re: What is wrong with you mr Compiler (mxmlc) ?
            ScreenMan Level 1

            Thanks for the answer.

             

            @hangxinghui, I already figured out that I could redefine the constructor in Bar using super thanks to the error message (which was quite clear).

            But still I don't find that behavior logic.

             

            Thing is if It compiles just fine without paramBelow:int which somewhat  means you normally don't need to override the constructor when you inherit.

            In other words you won't see "public function Bar () {super()}".

             

            Also for any other function than the constructor, if you want to define a function with or without parameter, you won't need to use that trick in the child class.

             

            Am I the only one that think that when you inherit a class, it should inherit the constructor by default (with or without parameters) like any other function ?

            • 3. Re: What is wrong with you mr Compiler (mxmlc) ?
              huangxinghui Level 1

              In other words you won't see "public function Bar () {super()}".

               

              --- class will generate this code by default. when you define class Bar {}, by default it will declare a default constructor with no argument like that