szisziszilvi
14th June 2011, 15:01
Hi,
I would like to use a QVector<double> for storing some data. The problem is that there is no guarantee that there will be data given for each possible entry, but the class QVector has 0 as the default value which would be actually a possible one (so would pretend as being a real measurement instead of showing clearly there is a missing data). This is it:
QVector<double> v(10);
for(int i = 0; i< 5; i++)
{
v[i] = i;
}
// v[5] and v[6] will be = 0
for(int i = 7; i< 10; i++)
{
v[i] = i;
}
for(int i = 0; i< 10; i++)
{
std::cout << v.at(i) ; // 0123450089
}
I don't want to use self-designed struct-s or store the boolean information if a real value was given or not in another array, but it would be nice if I could set my own fake value to change this 0 say to -999. This would also be a goal not to create a derived class just for this issue because the class in which I use this QVector should be normally used with as less extra documentation as possible. So it would be a bad habit telling one things like "for adding data use myVector class" or "before adding data make it sure you used the also provided 'cleanVector(double fakevalue)' function"). Something like "addData(QVector)" is straightforward enough to be used easily.
I would like to use a QVector<double> for storing some data. The problem is that there is no guarantee that there will be data given for each possible entry, but the class QVector has 0 as the default value which would be actually a possible one (so would pretend as being a real measurement instead of showing clearly there is a missing data). This is it:
QVector<double> v(10);
for(int i = 0; i< 5; i++)
{
v[i] = i;
}
// v[5] and v[6] will be = 0
for(int i = 7; i< 10; i++)
{
v[i] = i;
}
for(int i = 0; i< 10; i++)
{
std::cout << v.at(i) ; // 0123450089
}
I don't want to use self-designed struct-s or store the boolean information if a real value was given or not in another array, but it would be nice if I could set my own fake value to change this 0 say to -999. This would also be a goal not to create a derived class just for this issue because the class in which I use this QVector should be normally used with as less extra documentation as possible. So it would be a bad habit telling one things like "for adding data use myVector class" or "before adding data make it sure you used the also provided 'cleanVector(double fakevalue)' function"). Something like "addData(QVector)" is straightforward enough to be used easily.