D
Dejfson
Dear All,
can someone clarify me how to return the reference to the empty object
in case of error?
_not working_ Example of what i'd like to do:
const MyClassData& MyClass ()
{
QListIterator<MyClassData> it(fancylist)
while (it.hasNext())
{
const MyClassData &data = it.next();
if (data are ok)
return data;
}
return MyClassData();
}
This compiles, but of course it returns invalid reference in the case
when I don't find any suitable data. It there a way how to use the
reference in such case??
I have just one solution in my mind: if I create class variable:
class MyClass {
public:
MyClass () : errorVariable() {};
private:
MyClassData errorVariable;
}
and then I modify function:
const MyClassData& MyClass ()
{
QListIterator<MyClassData> it(fancylist)
while (it.hasNext())
{
const MyClassData &data = it.next();
if (data are ok)
return data;
}
return errorVariable;
}
But I'm not sure whether I like the idea of creating additional variable
just as placeholder for something which doesn't really exist..
Is there another way?
thx
d.
can someone clarify me how to return the reference to the empty object
in case of error?
_not working_ Example of what i'd like to do:
const MyClassData& MyClass ()
{
QListIterator<MyClassData> it(fancylist)
while (it.hasNext())
{
const MyClassData &data = it.next();
if (data are ok)
return data;
}
return MyClassData();
}
This compiles, but of course it returns invalid reference in the case
when I don't find any suitable data. It there a way how to use the
reference in such case??
I have just one solution in my mind: if I create class variable:
class MyClass {
public:
MyClass () : errorVariable() {};
private:
MyClassData errorVariable;
}
and then I modify function:
const MyClassData& MyClass ()
{
QListIterator<MyClassData> it(fancylist)
while (it.hasNext())
{
const MyClassData &data = it.next();
if (data are ok)
return data;
}
return errorVariable;
}
But I'm not sure whether I like the idea of creating additional variable
just as placeholder for something which doesn't really exist..
Is there another way?
thx
d.