On Tue, 04 Oct 2011 16:16:00 +0200, softwareEngineer wrote:
Yes, but I need a vector of generic value (float, int, ecc.)
In which case, the values need a common base class, e.g.:
class MY_Value {
...
};
template <typename T>
class MY_Value_T : public MY_Value {
...
};
std::vector<MY_Value*> v;
MyValue_T<int> iV1 = 1;
MyValue_T<float> iV2 = 2.1;
v[0] = static_cast<MY_Value*>(&iV1);
v[1] = static_cast<MY_Value*>(&iV2);
Casting the vector elements back to their correct type is a bit more
involved, as you need to know what their correct type is, either by
using RTTI or by explicitly adding a tag field to the base class.
If you need this, use boost::any. It's close to this, but exposes