Calling Base Class' Ctor

B

BDB

Hi,

I'm trying to call a base class' constructor. This is giving me an error:
Use of keyword 'base' is not valid in this context.

....

public class B : A
{
B( int i )
{
base( i ) //Calling A's ctor of same declaration
}
}


Thanks,
Bryan
 
J

JaredHite1

You have to call it before the function body, like so:
public class B : A
{
B( int i ) : base( i )
{
}
}

Good luck,
Jared
 
B

BDB

BDB said:
Hi,

I'm trying to call a base class' constructor. This is giving me an error:
Use of keyword 'base' is not valid in this context.

...

public class B : A
{
B( int i )
{
base( i ) //Calling A's ctor of same declaration
}
}


Thanks,
Bryan

Found it.

public class B : A
{
B( int i ) : base( i ) {}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top