c# - Referencing a class that inherits from another class -
i creating library , referencing class main inherits body
public class main:body
i added main using references when go initiate instance - tried:
main _main = new main()
underlines new main()
saying doesn't contain constructor takes 0 arguments.
how can adjust referencing class - need included inherited class well?
main _main = new main()
underlines newmain()
saying doesn't contain constructor takes 0 arguments.
it's telling problem is. there isn't public constructor on main
takes 0 arguments.
you need 1 of following:
- add public constructor takes 0 arguments:
public main() { }
. - invoke different constructor public on
main
class: if signaturepublic main(object o)
you'dmain _main = new main(o)
o
object.
let's @ example:
class foo { public foo() { } }
this class has public constructor 0 arguments. therefore, can construct instances via
foo foo = new foo();
let's @ example:
class bar { public bar(int value) { } }
this class not have public constructor 0 arguments. therefore, can not construct instances via
bar bar = new bar(); // not legal, there no such constructor // compiler yell
but can say
bar bar = new bar(42);
here's 1 more:
class foobar { }
this class does have public constructor 0 arguments. because if not provide any constructors, compiler automatically provide public constructor 0 arguments by default. thus, legal:
foobar foobar = new foobar();
Comments
Post a Comment