M
MattWilson.6185
Hi, I was wondering if there is any type of way to specify a generic
type for a list. I basicaly have
class shape {
}
class circle: public shape {
};
class triangle: public shape {
};
template <class T>
class red : public T {
}
template <class T>
class blue : public T {
}
template <class T>
class Blueish : public blue<T> {
}
now I have a class that manages all blueish objects
class BlueishManager {
public:
void Add(Blueish<shape>* ent) ....
private:
list<Blueish<shape>* > __list;
}
The problem is casting a Blueish<triangle> to a Blueish<shape> causes
all the functions of the Blueish<triange> to be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)
list<Blueish<? shape>*> __list; So I don't have to cast my objects to
add them?
Right now I have to have a diffrent list for each object
list<Blueish<triangle>*> __listTriangle;
list<Blueish<circle>*> __listCircle;
but that might be a pain later if I add a new shape!
Thanks
Matt
type for a list. I basicaly have
class shape {
}
class circle: public shape {
};
class triangle: public shape {
};
template <class T>
class red : public T {
}
template <class T>
class blue : public T {
}
template <class T>
class Blueish : public blue<T> {
}
now I have a class that manages all blueish objects
class BlueishManager {
public:
void Add(Blueish<shape>* ent) ....
private:
list<Blueish<shape>* > __list;
}
The problem is casting a Blueish<triangle> to a Blueish<shape> causes
all the functions of the Blueish<triange> to be overwritten. The shape
part still will call all of the Triangle data, but I create a new
Blueish class. Is there anyway I can make a functions like in java
(I'm no java programer but I have seen it)
list<Blueish<? shape>*> __list; So I don't have to cast my objects to
add them?
Right now I have to have a diffrent list for each object
list<Blueish<triangle>*> __listTriangle;
list<Blueish<circle>*> __listCircle;
but that might be a pain later if I add a new shape!
Thanks
Matt