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 new main() 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:

  1. add public constructor takes 0 arguments: public main() { }.
  2. invoke different constructor public on main class: if signature public main(object o) you'd main _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

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -