Re: NULL
Ya, the failure of the condition indicates a parse error. I want to
just print an intelligent
error message when that happens and want the program to exit. What's
the best way to do that?
Also, I am now trying to return a pointer but the program exits with a
segmentation fault. I am sorry
i am not quite good with pointers. Here is the code i am using. Is
something wrong with it?
ClassName * funcName(string name)
{
deque<ClassName> tempDeque = someGlobalClassNameDeque;
deque<ClassName>::iterator tempDequeIterate;
tempDequeIterate = tempDeque.begin();
while (tempDequeIterate != tempDeque.end())
{
ClassName * tempClassName = new ClassName();
ClassName temp = *tempDequeIterate;
*tempClassName = temp;
if (name == temp->name)
return tempClassName;
tempDequeIterate++;
}
return NULL;
}
int main()
{
ClassName * p = funcName(someString);
if (p == NULL)
{
parseError(someString + " undefined.");
}
else
{
toRet = anotherFunc(*p);
}
return toRet;
}
Any suggestions/comments would be appreciated.
Thank you,
Mohit
On Jun 22, 3:08 am, Rolf Magnus <ramag...@t-online.de> wrote:
Mohitz wrote:
How do you write a function in C++ which returns a class object in
some cases and in others, returns something like a NULL pointer so
that i can know in the callee function that the object doesnt exist??
ClassName A()
{
ClassName a;
if (condition)
return a;
else
throw some_exception();