T does not contain a definition

Hello,

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
        }
    }

I think you should use this?

 public Dictionary<HexTile.TerrainType, int> _weights = new Dictionary<HexTile.TerrainType, int>();

Hey Methos,

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.

Not sure what’s wrong here

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?

1 Like

The plan is to use HexTile as a base class and then extend from there. So hopefully if I constrain to the base class all the methods should work

OK… but… I still don’t see why you wanted to use T.TerrainType instead of HexTile.TerrainType. Just use HexTile.TerrainType.

I was hoping I could use the child of HexTile because it will mask the base in some cases. Is the enum type an issue for generic classs ?

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.

Ahh ok im an idiot, your right i see my no sense logic here

Thanks for all the help