Ctor issue in subclasses...

May 27 2008 1:29 PM

Hi gang,

For some reason the "search forum" bit is not working on my machine - I keep getting pitched to an error page.

Please feel free to re-direct me to a prior thread (sans flame) if this has (most likely it has) been already covered.

I am an old-time OO developer, but I came up through the glorious world of Smalltalk (can you tell where my allegiances lie?).  In ST, if you wanted to make a subclass you created the subclass, and then any constructors (actually ST does not have the notion of constructors enforced), would be called automatically up the hierarchy.  So if I had Class X subclassing Class A, and A implemented foo(x, y).  I could create an instance of X and say X foo(1, 2).  The engine would figure out the correct method to invoke.

C# does not seem to work this way... and my C++ chops are so old, I am embarrassed to say where I left off there.

How do I invoke a simple ctor in Class A from a X?  Currently I have

public OutputLayer(int i, int o)

{

numInputs = i;

numOutputs = o;

}

 

public class MiddleLayer : OutputLayer

{

...

}

And I am trying to do something like

MiddleLayer ml;

ml = new MiddleLayer(layerSize[i], layerSize[i + 1]);

 

When I compile, I get

Error 5 'NeuralNetworks.MiddleLayer' does not contain a constructor that takes '2' arguments C:\Documents and Settings\CBurns\My Documents\Visual Studio 2008\Projects\NeuralNetworks\KSOM_Console\Network.cs 79 33 KSOM_Console

Why is the compiler not resolving to the base class' ctor?

Thanks for any input!

Chris


Answers (2)