954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

What is the best value for an empty point in C++?

I don't ensure whether "0" or "NULL" is better to be an empty point's value in C++. Could anybody can tell me,and why?
Then how about it in C, why?

Thank you!

meiyantao
Light Poster
31 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

As answered by Stroustrup:

In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer. In pre-standard code, NULL was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days.
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 
Just because it is possible to push twigs along the ground with one’s nose does not necessarily mean that that is the best way to collect firewood.



I am sorry for that I can't understand what's this sentence's meaning? My English is poor.
Can you tell me what is your opinion in whether use "NULL" in C++?

Thank you very much !

meiyantao
Light Poster
31 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

>I am sorry for that I can't understand what's this sentence's meaning?
Where did you find that sentence? It's nowhere in this thread.

>Can you tell me what is your opinion in whether use "NULL" in C++?
0 and NULL are the same thing in C++. Pick one and use it consistently.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

> Where did you find that sentence? It's nowhere in this thread.
Yes, its my damned signature. :D

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

Get a more interesting signature! If I don't notice it, it's not worth reading.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Pushing twigs with one's nose never was interesting... :-)

Plus, the more interesting my signatures become, the more debate it sparks and more are the threads created in the Moderators Place. ;-)

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

The Moderator's Place has been too slow anyway. If you want, I can suggest one:
I hate VB.NET’s continuous bloody interference. I HADN’T FINISHED TYPING YET YOU STUPID COMPILER! CAN’T YOU SEE THAT? DOES IT LOOK TO YOU LIKE I’M DONE TYPING? DID IT NOT OCCUR TO YOU THAT THE REASON YOU’VE FOUND ALL THOSE ERRORS IS BECAUSE I’M NOT FINISHED YET?!! I’LL TELL YOU WHEN I WANT YOU TO CHECK MY WORK, AND NOT BEFORE!

-- Ian Griffiths
Ah, that guy can totally read my mind. ;)

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Heh good one. But since it seems that I seem to be the center of most discussions there, maybe its time someone else started playing the part of a scape goat. ;-)

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

I can't imagine why you're so popular. I'm several orders of magnitude worse than you and nobody bats an eyelash. :icon_rolleyes: Maybe you're too nice. Try being meaner and you'll be accepted.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

> I can't imagine why you're so popular.
Friendly would be more like it.

> I'm several orders of magnitude worse than you and nobody bats an eyelash.
Maybe they have got used to you.

> Maybe you're too nice. Try being meaner and you'll be accepted.
Maybe an official training from you would do the job. ;-)

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

:sweat: En,this,that......English sometimes is more important than C++,Ha!

But I have another intresting questions:
What's the differences between struct and class(all member is public)?
Look at these codes:

BinarySearchTree.h

BinarySearchTree.cpp

main.cpp


When I compiled them with Dev-cpp(gcc4.1 compiler) in windows,the command line is like this:> g++ -Wall -o main.exe main.cpp BinarySearchTree.cpp
BinarySearchTree.cpp:116: error: expected constructor,destructor,or type conversion before '*' token
BinarySearchTree.cpp:123: error: expected constructor,destructor,or type conversion before '*' token
BinarySearchTree.cpp:165: error: expected constructor,destructor,or type conversion before '*' token

I think the errors from the class BinaryNode. When Weiss write it,he use the "BinaryNode sturct",most of the others are the same.

My friends told me to study OOP, so I didn't use the template for simple. And he say that the "BinaryNode sturct is too 'C' ",then I rewrite it to class. But the problems comes

I need your help to know :
1.What's the differences between struct and class(all members is public)?
2.How to make this program runs?

Thanks!

Attachments BinarySearchTree.h (1.57KB) BinarySearchTree.cpp (4.3KB) main.cpp (0.23KB)
meiyantao
Light Poster
31 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

>What's the differences between struct and class(all member is public)?
Default access to a class is private and default access to a struct is public.

>And he say that the "BinaryNode sturct is too 'C'
It sounds like he doesn't know what he's talking about. Rather than follow bad advice, first learn how trees work and then look at the different ways you can implement them.

>2.How to make this program runs?
My recommendation is to stop using classes. Trying to contain a tree structure into a class just complicates everything by adding an extra layer of fat. It's easier to learn how to use trees with just a structure and a few functions and then add a class framework later.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
>What's the differences between struct and class(all member is public)? Default access to a class is private and default access to a struct is public. >And he say that the "BinaryNode sturct is too 'C' It sounds like he doesn't know what he's talking about. Rather than follow bad advice, first learn how trees work and then look at the different ways you can implement them. >2.How to make this program runs? My recommendation is to stop using classes. Trying to contain a tree structure into a class just complicates everything by adding an extra layer of fat. It's easier to learn how to use trees with just a structure and a few functions and then add a class framework later.




I believe that it is a good recommendation to stop using classes.
But I want to prictice OOP with C++ as well as implement the tree.

I want to write ALV tree whic will inherit form the BinarySearchTree.
I kown it's a foolish design to do so,but I haven't write a program with herit ever. So I want to try to do it.

Ah,do you know that C and C++ is looked as the water and fire in China! If someone use C style code in *.cpp,he will be considered as a laypeople.

Could you tell me why the code can't pass the compiler?
Thanks.

meiyantao
Light Poster
31 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

You're making everything harder by trying to do too much, too soon. I don't care if you try, but I'm not going to help you run yourself into a wall.

>Ah,do you know that C and C++ is looked as the water and fire in China!
>If someone use C style code in *.cpp,he will be considered as a laypeople.
Not just China. Clueless people all over the world seem to think that C-style code in C++ is somehow less "pure". They're wrong, of course, and you shouldn't listen to them.

>Could you tell me why the code can't pass the compiler?
Do a Google search for PEBKAC and you'll discover the problem.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You