472,354 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 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 12791
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
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...

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.