Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Beginners Question: How to return "NULL"
Beginners Question: How to return "NULL" [message #6675] Wed, 22 November 2006 14:31 Go to next message
WebChaot is currently offline  WebChaot
Messages: 53
Registered: September 2006
Location: Austria, Vienna
Member
Hi all!

Maybe a stupid question - but how to return "NULL":

I have a function which usually returns an object. But if no object is under the mouse position I want to return something like Null.

But not possible, because "invalid initialization of non-const reference of type 'PosObject&' from a temporary of type 'int'".

Here is the code:

==========================================================
xObject& xLayout :: GetObject(int id)
{
for (int i = xObjects.GetCount() - 1; i >= 0; i--)
{
if (xObjects.At(i).GetId() == id)
{
return xObjects.At(i);
}
}

return NULL; <<< === doesn't work
}
==========================================================



Thanks in advance,

WebChaot
Re: Beginners Question: How to return "NULL" [message #6676 is a reply to message #6675] Wed, 22 November 2006 14:37 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Reference cannot be NULL.

I recommend to make it return pointer (xObject *) instead.

(For me, this is the rule of thumb - if something can be NULL, it is pointer...)

Mirek
Previous Topic: Clear Vector< Vector<*> >
Next Topic: Double formatting bug?
Goto Forum:
  


Current Time: Sun Apr 28 07:59:23 CEST 2024

Total time taken to generate the page: 0.05176 seconds