Originally Posted by
Narue
>What to return?
An exception is the better option in this case. But if you want to return something, you need to pick a string that couldn't possibly be in the database. That's difficult to do, so you might do well to add a level of indirection by using an object for each cell rather than a string. Then you can easily give it a null value and any other cellish information that isn't easily derived from the value:
class Cell {
bool is_null;
std::string value;
public:
Cell ( const std::string& init = "" )
: is_null ( init.size() == 0 ), value ( init )
{}
public:
const std::string& GetValue() const
{
return value;
}
void SetValue ( const std::string& s )
{
value = s;
is_null = false;
}
bool IsNull() const
{
return is_null;
}
};
Thank u very much.
But I still have a question, if I write something like this
const Cell & Test() {
return NULL; //I just want to tell something is wrong
}
Of course, I defined a copy constructor in Class Cell like this
Cell(const int i) {
if(0 == i) is_null =true;
}
But it doesn't work well, there is a waring "returning address of local
variable or temporary". I know that, a temp object is generated in
Test and the reference of that object is returned.
In fact, i think Test() returns a reference of something, it must be
a long life object(i mean not temp or local). But at that time, i don't
have such a object, how to return?
Thank you