wondering if someone can take a quick look at my generic definition, not sure what im missing (all classes are under same namespace)
public class HexSphereGeneric<T,U>
where T : HexTile
where U : HexTri
{
public Dictionary<T.TerrainType, int> _weights = new Dictionary<T.TerrainType, int>(); /// Error not defined
}
public class HexTile
{
// all terrain types
public enum TerrainType
{
Terrain_INHERIT,
Terrain_WATER,
Terrain_DESERT,
Terrain_GRASSLAND,
Terrain_FOREST,
Terrain_MOUNTAIN
}
}
Thanks for the reply. Im actually trying to get HexTile.TerrainType to be a genetic type since Im planning on having permutation of HexTile class. eg public class HexSphereGeneric<T,U> where T is maybe a nav node.
I’m not entirely sure what you’re trying to do here.
You’ve stipulated that T must be assignable from HexTile. TerrainType is in HexTile. Therefore any class that inherits from HexTile will also have the TerrainType enum. How were you planning to override the TerrainType enum?
In other words, how would T.TerrainType make sense? How would it differ from HexTile.TerrainType?
An enum is a type, you can’t override it in a subclass. In fact, it doesn’t necessarily make sense to put enums in classes unless you are constraining the enum to be used only in that class or it is really strongly tied up with the concept represented by the class. Types like a class, struct, delegate or enum can stand on their own in a namespace.
Try describing more generally what you are trying to do and maybe someone will have an idea how to represent it in code.