Strange error with constructors

  • Thread starter Thread starter Fernando Rodríguez
  • Start date Start date
F

Fernando Rodríguez

Hi,

If I try to compile the code below, I get a weird error that seems to be
related with hte constructors.

-------------------------------------
class Action : System.Object
{
Object _something;

public Action( Object something )
{
_something = something;
}

public virtual void go()
{
Console.WriteLine(_something.ToString());
}
}


class Prueba : Action
{


public override void go()
{
Console.Write("Prueba says: ");
base.go();
}
}

--------------------------------------------

The error says something like: no overload for the method Action requires 0
arguments.

What the Hell does this mean? O:-)

Thanks
 
When inheriting a base class you effectivly will cause the CLR to create an
instance of that base class.

Since your base class only have one constructor, and that constructor needs
a parameter. The CLR cannot create the base object.

To make this work, you need to supply the parameter to the base class from
the sub class.

Btw, what does Prueba mean ;)

<code>
class Prueba : Action
{
public Prueba() : base(null)
{}

public override void go()
{
Console.Write("Prueba says: ");
base.go();
}
}
</code>
 
When inheriting a base class you effectivly will cause the CLR to create an
instance of that base class.

Since your base class only have one constructor, and that constructor needs
a parameter. The CLR cannot create the base object.

To make this work, you need to supply the parameter to the base class from
the sub class.

OK, I got it now. :-)
Btw, what does Prueba mean ;)

Test. :-)
 
Back
Top