473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

null object in c++

Hi,
In some cases when my function returns, I need to return a object of
null state. This is when I return object by value.
(Just like for by pointer, I can return a null pointer ).
It has to be equivalent to null (or uninitialized state) , just
like null iterator (or end iterator) .
has someone worked with the concept of a generic null object , i.e
any object with a null object trait can be treated as null object or
like that, with their value comparison semantic etc, so that I dont
need to define a null state for each class I create explicitly.

Thanks
abir

Mar 8 '07 #1
3 12875
toton wrote:
Hi,
In some cases when my function returns, I need to return a object of
null state. This is when I return object by value.
(Just like for by pointer, I can return a null pointer ).
It has to be equivalent to null (or uninitialized state) , just
like null iterator (or end iterator) .
has someone worked with the concept of a generic null object , i.e
any object with a null object trait can be treated as null object or
like that, with their value comparison semantic etc, so that I dont
need to define a null state for each class I create explicitly.

Thanks
abir
Why don't you just throw an exception when you can't return a fully
constructed object?

Ben
Mar 8 '07 #2
benben wrote:
toton wrote:
>Hi,
In some cases when my function returns, I need to return a object of
null state. This is when I return object by value.
(Just like for by pointer, I can return a null pointer ).
It has to be equivalent to null (or uninitialized state) , just
like null iterator (or end iterator) .
has someone worked with the concept of a generic null object , i.e
any object with a null object trait can be treated as null object or
like that, with their value comparison semantic etc, so that I dont
need to define a null state for each class I create explicitly.

Thanks
abir

Why don't you just throw an exception when you can't return a fully
constructed object?

Ben
Ok fair enough, I see your point. If you don't want to throw an
exception, then you need to

1) somehow design the class so they can represent a null state;
2) have a null object to compare to. Typically, class Null{}; Null null;
will do; and
3) define operator == and !=

Ben
Mar 8 '07 #3
"toton" <ab*******@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
: Hi,
: In some cases when my function returns, I need to return a object of
: null state. This is when I return object by value.
: (Just like for by pointer, I can return a null pointer ).
: It has to be equivalent to null (or uninitialized state) , just
: like null iterator (or end iterator) .
: has someone worked with the concept of a generic null object , i.e
: any object with a null object trait can be treated as null object or
: like that, with their value comparison semantic etc, so that I dont
: need to define a null state for each class I create explicitly.

You may want to consider boost::optional, or at least be interested in
the discussion at http://www.boost.org/libs/optional/doc/optional.html

Regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com

Mar 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jim Marquardson | last post by:
Hi, I've struggled with this for a while now, so I'm asking for help. I am trying to click on a link in one page, have that link open up in a new window, and set that newly opened window's...
8
by: Robert | last post by:
Hello all, Why reference cannot be able to represent a NULL object? Best regards, Robert
2
by: Pathogenix | last post by:
Greetings, I'm trying to fix a web service client which has been implemented in a dailywtf worthy manner. I've decided to rip all the old code out and start again from the proxy generated by...
15
by: Tarun Mistry | last post by:
Hi guys, what is the best/correct way to check for a NULL object? I.e. myClass test; if(test == null) {}
2
by: Glenn | last post by:
Rather than... if ( myInstance != null ) { myInstance.Dispose(); } maybe something like this... myInstance?Dispose();
0
by: anchiang | last post by:
Hi All, I have XML: <RegistryResponse status="Success" xmlns="urn:oasis:names:tc:ebxml-regrep:registry:xsd:2.1"> <AdhocQueryResponse xmlns="urn:oasis:names:tc:ebxml-regrep:query:xsd:2.1"> ...
1
by: JWest46088 | last post by:
I'm getting this error when I try to preview my code: TypeError: Error #1009: Cannot access a property or method of a null object reference. at therun4life_fla::MainTimeline/frame1() I don't...
3
karthickkuchanur
by: karthickkuchanur | last post by:
Dear Experts, Please let me know what is the difference between difference between object !=null and null !=object,I already google it but i can't able to find the right answer
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.