Anonymous user
Null object: Difference between revisions
no edit summary
(→{{header|PureBasic}}: Added PureBasic) |
No edit summary |
||
Line 93:
=={{header|C++}}==
In C++
<lang cpp>#include <iostream>
#include <cstdlib>
if (object ==
std::cout << "object is null";
}</lang>
boost::optional is available for cases where the programmer wishes to pass by value, but still support a null value.
<lang cpp>
#include <boost/optional.hpp>
#include <iostream>
boost::optional<int> maybeInt()
int main()
{
boost::optional<int> maybe = maybeInt();
if(!maybe)
std::cout << "object is null\n";
}
</lang>
=={{header|C sharp|C#}}==
As with Java, any reference type may be null, and testing for nullity uses ordinary boolean operators.
|