I have a generic class with the following constructors 1. Map(int resolution)
, 2. Map(int resolution, T defaultValue)
, 3. Map(int width, int height)
and 4. Map(int width, int height, T defaultValue)
, what happens if one of the inheriting classes requires map<int>, constructors 2 and 3 each have 2 parameters and in the map<int> case they would both be integers.
public abstract class Map<T> {
private T[,] m_Map;
private T m_DefaultValue;
public T this[int x, int y] {
get {
return InRange(x,y)?m_Map[x,y]:DefaultValue;
}
set {
if(InRange(x,y)) { // Included to handle confusion between retrieving a non-existent position, and setting one.
m_Map[x,y] value;
}
}
}
public int Width{get { return m_Map.GetLength(0); } }
public int Height{get { return m_Map.GetLength(1); } }
public virtual T DefaultValue { get { return m_DefaultValue; } set{ m_DefaultValue = value; } }
public Map(int resolution) : this(resolution, resolution, default) {}
public Map(int resolution, T defaultValue) : this(resolution, resolution, defaultValue) {}
public Map(int width, int height) : this(width, height, default) {}
public Map(int width, int height, T defaultValue) {
m_Map = new T[width, height];
m_DefaultValue = defaultValue;
}
public bool InRange(int x, int y) {
return x>=0&&x<m_Map.GetLength(0)&&y>=0&&y<m_Map.GetLength(1);
}
}