6

I know that different functions can have the same name but take different parameters. For instance, the truffle assert library has equalities and inequalities on lots of datatypes. But I just tried to do the same for a constructor and got a compiler complaint. I'd like to be able to say

contract Foo { function Foo (uint onearg) { return Foo(onearg, 2); } function Foo (uint onearg, uint secondarg) { ... do the real work ... } }

1 Answer 1

8

No, from the docs, "A constructor is optional. Only one constructor is allowed, and this means overloading is not supported."

1
  • Thanks. I looked for that, and failed. Unfortunate. I wonder if there are plans to allow it. Commented Feb 27, 2018 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.