473,466 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with checking if class is NULL

Hello all,

Ok, I am taking a C++ class at a local community college, and I'm
working on a small program for my own learning needs and I ran into a
problem.

The class I'm building includes a pointer to another object of the
same class, so that I can loop through the objects, using the objects
Next_Object() member function which returns the adress of the next
object in the list.

In my loop I am setting a pointer to the class to what Next_Object()
returns, and I need to check if that is NULL in order to exit the loop
(i.e tmp_object != NULL). Here is where my problem is. The compiler
says that I need to overload the != operator to do this, but if the
object is NULL, how would it call it's member function?

Any help would be appreciated.
- TwinkiE_HunteR-G strikes again!
: tw**************@hard-wire.net
: HARD-WiRE Web Design
: http://www.hard-wire.net
Jul 22 '05 #1
9 2895
On Thu, 08 Apr 2004 03:11:02 GMT, TwinkiE_HunteR-G
<tw********************@hard-wire.net> wrote in comp.lang.c++:
Hello all,

Ok, I am taking a C++ class at a local community college, and I'm
working on a small program for my own learning needs and I ran into a
problem.

The class I'm building includes a pointer to another object of the
same class, so that I can loop through the objects, using the objects
Next_Object() member function which returns the adress of the next
object in the list.

In my loop I am setting a pointer to the class to what Next_Object()
returns, and I need to check if that is NULL in order to exit the loop
(i.e tmp_object != NULL). Here is where my problem is. The compiler
says that I need to overload the != operator to do this, but if the
object is NULL, how would it call it's member function?

Any help would be appreciated.


There must be a difference between the description that you posted and
the code that you didn't. Any pointer to any object type, and even
pointers to functions can be compared to NULL. If your compiler does
not accept this, what you are trying to compare is NOT a pointer.

Post the smallest possible code sample that show problem, with the
definitions of the data types.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #2
On Thu, 08 Apr 2004 03:11:02 GMT, TwinkiE_HunteR-G
<tw********************@hard-wire.net> wrote in comp.lang.c++:
Hello all,

Ok, I am taking a C++ class at a local community college, and I'm
working on a small program for my own learning needs and I ran into a
problem.

The class I'm building includes a pointer to another object of the
same class, so that I can loop through the objects, using the objects
Next_Object() member function which returns the adress of the next
object in the list.

In my loop I am setting a pointer to the class to what Next_Object()
returns, and I need to check if that is NULL in order to exit the loop
(i.e tmp_object != NULL). Here is where my problem is. The compiler
says that I need to overload the != operator to do this, but if the
object is NULL, how would it call it's member function?

Any help would be appreciated.


There must be a difference between the description that you posted and
the code that you didn't. Any pointer to any object type, and even
pointers to functions can be compared to NULL. If your compiler does
not accept this, what you are trying to compare is NOT a pointer.

Post the smallest possible code sample that show problem, with the
definitions of the data types.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #3
TwinkiE_HunteR-G wrote:
In my loop I am setting a pointer to the class to what Next_Object()
returns, and I need to check if that is NULL in order to exit the loop
(i.e tmp_object != NULL). Here is where my problem is. The compiler
says that I need to overload the != operator to do this, but if the
object is NULL, how would it call it's member function?

Any help would be appreciated.


Are you sure tmp_object is a pointer?
Jul 22 '05 #4
TwinkiE_HunteR-G wrote:
In my loop I am setting a pointer to the class to what Next_Object()
returns, and I need to check if that is NULL in order to exit the loop
(i.e tmp_object != NULL). Here is where my problem is. The compiler
says that I need to overload the != operator to do this, but if the
object is NULL, how would it call it's member function?

Any help would be appreciated.


Are you sure tmp_object is a pointer?
Jul 22 '05 #5

"Jon Willeke" <j.***********@verizon.dot.net> schrieb im Newsbeitrag
news:4v******************@nwrdny03.gnilink.net...
TwinkiE_HunteR-G wrote:
In my loop I am setting a pointer to the class to what Next_Object() returns, and I need to check if that is NULL in order to exit the loop (i.e tmp_object != NULL). Here is where my problem is. The compiler says that I need to overload the != operator to do this, but if the object is NULL, how would it call it's member function?

Any help would be appreciated.


Are you sure tmp_object is a pointer?


And if it's not:
class A
{
public:
A(){}
~A(){}

A m_A;
};

int main(int, char**)
{
A myA;
}

This will get you some trouble, won't it? My compiler doesn't allow
it, does yours?
-Gernot
Jul 22 '05 #6

"Jon Willeke" <j.***********@verizon.dot.net> schrieb im Newsbeitrag
news:4v******************@nwrdny03.gnilink.net...
TwinkiE_HunteR-G wrote:
In my loop I am setting a pointer to the class to what Next_Object() returns, and I need to check if that is NULL in order to exit the loop (i.e tmp_object != NULL). Here is where my problem is. The compiler says that I need to overload the != operator to do this, but if the object is NULL, how would it call it's member function?

Any help would be appreciated.


Are you sure tmp_object is a pointer?


And if it's not:
class A
{
public:
A(){}
~A(){}

A m_A;
};

int main(int, char**)
{
A myA;
}

This will get you some trouble, won't it? My compiler doesn't allow
it, does yours?
-Gernot
Jul 22 '05 #7
On Thu, 8 Apr 2004 16:17:17 +0200, "Gernot Frisch" <Me@Privacy.net>
wrote:

"Jon Willeke" <j.***********@verizon.dot.net> schrieb im Newsbeitrag
news:4v******************@nwrdny03.gnilink.net. ..
TwinkiE_HunteR-G wrote:
> In my loop I am setting a pointer to the class to whatNext_Object() > returns, and I need to check if that is NULL in order to exit theloop > (i.e tmp_object != NULL). Here is where my problem is. Thecompiler > says that I need to overload the != operator to do this, but ifthe > object is NULL, how would it call it's member function?
>
> Any help would be appreciated.


Are you sure tmp_object is a pointer?


And if it's not:
class A
{
public:
A(){}
~A(){}

A m_A;
};

int main(int, char**)
{
A myA;
}

This will get you some trouble, won't it? My compiler doesn't allow
it, does yours?
-Gernot


OK, Im sorry for the trouble, I have been up for a couple of days when
I wrote this and I missed the single character to declare tmp_object
as a pointer. My apologizes and thanks for the quick and helpful
responses.
- TwinkiE_HunteR-G strikes again!
: tw**************@hard-wire.net
: HARD-WiRE Web Design
: http://www.hard-wire.net
Jul 22 '05 #8
On Thu, 8 Apr 2004 16:17:17 +0200, "Gernot Frisch" <Me@Privacy.net>
wrote:

"Jon Willeke" <j.***********@verizon.dot.net> schrieb im Newsbeitrag
news:4v******************@nwrdny03.gnilink.net. ..
TwinkiE_HunteR-G wrote:
> In my loop I am setting a pointer to the class to whatNext_Object() > returns, and I need to check if that is NULL in order to exit theloop > (i.e tmp_object != NULL). Here is where my problem is. Thecompiler > says that I need to overload the != operator to do this, but ifthe > object is NULL, how would it call it's member function?
>
> Any help would be appreciated.


Are you sure tmp_object is a pointer?


And if it's not:
class A
{
public:
A(){}
~A(){}

A m_A;
};

int main(int, char**)
{
A myA;
}

This will get you some trouble, won't it? My compiler doesn't allow
it, does yours?
-Gernot


OK, Im sorry for the trouble, I have been up for a couple of days when
I wrote this and I missed the single character to declare tmp_object
as a pointer. My apologizes and thanks for the quick and helpful
responses.
- TwinkiE_HunteR-G strikes again!
: tw**************@hard-wire.net
: HARD-WiRE Web Design
: http://www.hard-wire.net
Jul 22 '05 #9
Jon Willeke wrote:
Are you sure tmp_object is a pointer?


And just what is "NULL"? Use the proper 0.
Jul 22 '05 #10

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

Similar topics

1
by: Lentdave67t | last post by:
Thank you in advance for any help you can provide. I am writing a C# program that checks to see if the URLs of favorites/bookmarks are still good. The problem I am having is that while the...
2
by: Lentdave67t | last post by:
Thank you in advance for any help you can provide. I am writing a C# program that checks to see if the URLs of favorites/bookmarks are still good. The problem I am having is that while the...
1
by: ashish | last post by:
We are working on development of an IFilter component for Jpeg and tiff files.First ever test resulted in following error. We are using ifilttst.exe(which comes with windows 2003 resource kit.) to...
14
by: TwinkiE_HunteR-G | last post by:
Hello all, Ok, I am taking a C++ class at a local community college, and I'm working on a small program for my own learning needs and I ran into a problem. The class I'm building includes a...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
5
by: dav3 | last post by:
I am by no means an ultra slick programmer and my problem solving skills.. well they leave much to be desired. That being said I have been working on the following problem for the past few days and...
6
by: gasfusion | last post by:
I wrote a class Min-Max Heap Template Class which works perfectly fine with integers. As part of this data structure, i have to implement some sort of method to check for the smallest...
8
by: Chris | last post by:
Hi, i have in an content page a fieldset containing a label, an iframe and a textarea: <asp:Content ID="Content1" ContentPlaceHolderID="main" Runat="Server"> <fieldset style="width:650px;">...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.