F
fabricio.olivetti
I am designing a class to read a data file and provide access to
another class, but as this dataset may contain either double or int
values, and some of them may be very large I'd like to create a class
that can decide upon allocating a vector of "char" (for the integral
values may be enough) or a vector of double.
But I can't see how can I do that...using templates I still have to
determine, prior the class declaration, which type this class will
hold.
Of course I could declare something like this:
class foo{
private:
vector< char > cData;
vector< double > dData;
bool type;
public:
double getData(unsigned i);
};
and always return a double (casting the char when required) and using
just the required data type using a flag to determine which type is
used by the class.
How would be the most elegant and optimized way of doing that?
Regards,
Fabricio
another class, but as this dataset may contain either double or int
values, and some of them may be very large I'd like to create a class
that can decide upon allocating a vector of "char" (for the integral
values may be enough) or a vector of double.
But I can't see how can I do that...using templates I still have to
determine, prior the class declaration, which type this class will
hold.
Of course I could declare something like this:
class foo{
private:
vector< char > cData;
vector< double > dData;
bool type;
public:
double getData(unsigned i);
};
and always return a double (casting the char when required) and using
just the required data type using a flag to determine which type is
used by the class.
How would be the most elegant and optimized way of doing that?
Regards,
Fabricio