Jump to content
  • Advertisement
Sign in to follow this  
Rich Brighton

c# instantiating abstract class in an abstract class

This topic is 2703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got an abstract base class Hex and and I'm instantiating an array of Hex in an abstract base class Scenario. In the derived class ScenarioC I instantiate an array of HexC. HexC is derived from Hex

namespace RichStrat
{
public abstract class Hex
{
public List<long> unitIds;
}
}

namespace RichStrat
{
public class HexC: Hex
{
public Terr terr;

public HexC()
{
terr = Terr.Plain;
unitIds = new List<long> { };
}
}
}

namespace RichStrat
{
public abstract class Scenario
{
public long xDim;
public long yDim;
public DateTime currGameTime;
public Hex[,] hexs;
public List<Unit> units;
}
}


namespace RichStrat
{
public class ScenarioC: Scenario //The Core Database for the game scenario. Theoretically multiple secenarios can be loaded into memory at the same time
{
public HexC[,] hexs; /But when I comment this line out it still compiles
public ScenarioU[] userView; // A database for every user and AI entity

public ScenarioC(TestScenario t)
{
xDim = 4;
yDim = 5;
hexs = new HexC[xDim, yDim];
for (long x = 0; x < xDim; x++)
{
for (long y = 0; y < yDim; y++)
hexs[x, y] = new HexC();
}
units = new List<Unit> () {};
units.Add(new Unit(this, units.Count, 3,3));

}
public void InitUserData()
{


}

}
}

But when I comment out the line:

public: HexC[,] hexs; // It still compiles.

Haven't I just instantiated an abstract class?

Edit: Ah silly me! I've just realised that I'm not instantiating any Hex only an array of Hex.Should I be using an interface instead here to force the derived Classes of scenario to implement a Hex derived Class?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!