A simple example of what i mean, plain old C style nothing much of C++,
double v[10];
QVector<double*> pv(10);
for(int i = 0; i < pv.size(); i++)
{
if((i == 5) or (i == 6)) //no 6th and 7th elements
pv = 0;
else
pv = &v[i];
}
for(i = 0; i < pv.size(); i++)
{
if(pv[i])
std::cout << *(pv.at(i)) ; //01234789
}
double v[10];
QVector<double*> pv(10);
for(int i = 0; i < pv.size(); i++)
{
if((i == 5) or (i == 6)) //no 6th and 7th elements
pv = 0;
else
pv = &v[i];
}
for(i = 0; i < pv.size(); i++)
{
if(pv[i])
std::cout << *(pv.at(i)) ; //01234789
}
To copy to clipboard, switch view to plain text mode
This is very basic example. I am not very clear of you actual requirement behind this, but I understand you need a container which is capable to indicate not used elements. Unlike other programing languages (mostly scripting based), which have something line "nothing" / "not initialized" for not set variables, C / C++ does not have anything like this. One alternate way is to use default ctor to set a "not initialized" value (which in many cases is still a valid value, 0 in your case).
I see you might end-up having your own element class (not container class), or doing something like this example, or as already suggested using some other default value (-99999, NAN) other than 0.
Bookmarks