Class inheritance

  • Thread starter Thread starter MuZZy
  • Start date Start date
M

MuZZy

Hello,

I just started with c# and i am trying to port some java code. Here is a
simple sample of what i have on java:

public abstract class Element {
public Element( Element prev, Element parent, Element child ) {
<some code> }
public abstract double Exec();
}

public abstract class COperator extends Element {
public COperator( Element prev, Element parent, Element child ){
super(prev, parent, child ); // call base class constructor
}
}

So i have a base abstract class Element and inherited class Operator.
Now i try in C#:

public abstract class Element {
public Element( Element prev, Element parent, Element child ) {
<some code> }
public abstract double Exec();
}

public abstract class COperator : Element {
public COperator( Element prev, Element parent, Element child ){
//super(prev, parent, child ); - i don't know how to call base
class constructor here
}
}

C# compiler gives me an error: No overload for method Element takes '0'
arguments.

Can someone please help me?

Thank you,
Andrey
 
public COperator( Element prev, Element parent, Element child ) :
base(prev, parent, child )
{

}
 
...
public abstract class COperator : Element {
public COperator( Element prev,
Element parent, Element child ){
//super(prev, parent, child );
// i don't know how to call base
// class constructor here
}
}

C# compiler gives me an error: No overload for method
Element takes '0' arguments.

public abstract class COperator : Element
{
public COperator( Element prev, Element parent,
Element child ) : base (prev, parent, child)
{
}
}

In C# you use keyword "base" instead of "super".

Calling the superclass constructor (or other constructors of the same class
with "this" for that matter), must be made in the "initializer" right after
the signature of the constructor.

// Bjorn A
 
HI, i just tried with 'base',
first it wants me to include base ... in brackets,
second, compiler gives an error:

'MathParser.Element' denotes a 'class' which is nod valid in given context

Any ideas?
 
MuZZy said:
Hello,

I just started with c# and i am trying to port some java code. Here is a
simple sample of what i have on java:

public abstract class Element {
public Element( Element prev, Element parent, Element child ) {
<some code> }
public abstract double Exec();
}

public abstract class COperator extends Element {
public COperator( Element prev, Element parent, Element child ){
super(prev, parent, child ); // call base class constructor
}
}

So i have a base abstract class Element and inherited class Operator.
Now i try in C#:

public abstract class Element {
public Element( Element prev, Element parent, Element child ) {
<some code> }
public abstract double Exec();
}

public abstract class COperator : Element {
public COperator( Element prev, Element parent, Element child ){
//super(prev, parent, child ); - i don't know how to call base
class constructor here
}
}

C# compiler gives me an error: No overload for method Element takes '0'
arguments.

Can someone please help me?

Thank you,
Andrey
 
Hi MuZZy,
Read carefully what's in the posts. I think you used *base* in some wrong
way. You can post the code you try and we will tell you where is the error.
Again how the others said the right syntax is

public abstract class COperator extends Element
{
public COperator( Element prev, Element parent, Element
hild ):base(prev, parent, child )
{
}
}
 
Back
Top