View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Any C++ newbie or wants to learn pls read

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

19 replies to this topic

### #1TotalCoder  Members

Posted 10 December 2001 - 04:32 PM

Hi, Anyone interested in learning C++ please take a look at my tutorial and let me know what more I can change or add so that it better targets the novice. This tutorial is geared towards the complete novice and shows them how to get Borland C++ 5.5 up and running on the Windows platform. I would really appreciate your feedback. Please goto http://www.totalcoder.com and look at the Borland C++ 5.5 tutorial, and either post your comments and/or suggestions here or on the site. Sam ----- TotalCoder http://www.totalcoder.com "Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

### #2Null and Void  Members

Posted 10 December 2001 - 04:42 PM

You have a typo on your #include line (the less than and greater than). Use &lt; and &gt; for less than and greater than symbols, respectively. C++ compliance issues: You should be including iostream, not iostream.h; you should also use std::cout instead of cout if you do that (or put "using namespace std" in there somewhere). Somehow I doubt you should debate whether C or C++ is better in a compiler related tutorial, but to each his own I guess.

[Resist Windows XP''s Invasive Production Activation Technology!]

### #3polly  Members

Posted 11 December 2001 - 12:25 AM

Hi Sam,
Nice one. The tutorial is OK so far. One thing I''d suggest is a few screen shots of what you should actually see as you''re going through the process. I know it might sound a bit mickey mouse, but when youre just getting started youre very unsure of yourself...
Jon

### #4TotalCoder  Members

Posted 11 December 2001 - 05:21 AM

Thanks let me make those revisions, and the screen shot ideal is a good one. I forgot about the C++ compliance issues, since Visual C++ breaks a lot of them. They always include #include it made me forget it is #include .

Also with C++ header files should be named with .hpp extension. Let me get a rewrite and I''ll repost, did you find it helpful for the newbies?

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

### #5TotalCoder  Members

Posted 11 December 2001 - 05:23 AM

Null and Void,

I was trying not to debate whether C or C++ is better, I''m sorry it came off that way. I was merely trying to inform the reader on why I was using C++, but if it may be confusing for the newbie I''ll remove it.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

### #6Arild Fines  Members

Posted 11 December 2001 - 07:53 AM

void main is not valid C or C++. Using void to indicate an empty parameter list is not recommended in C++.

Psalm 137:9: "Happy shall he be, that taketh and dasheth thy little ones against the stones."

### #7krez  Members

Posted 11 December 2001 - 08:13 AM

quote:
Original post by Arild Fines
Using void to indicate an empty parameter list is not recommended in C++.

you mean
int SomeFunc(void) { ... };

right?
why not? i thought that was good form...

--- krez (krezisback@aol.com)

### #8TotalCoder  Members

Posted 11 December 2001 - 08:31 AM

Well for an explanation on why void main... is improper here is a direct quote from Bjarne on his site. Also, I am busily incorporating these changes and everything else into the first tutorial. Thanks again everyone!

quote:

Can I write "void main()"?
The definition
void main() { /* ... */ }

is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ }

and
int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn''t provide such a facility the return value is ignored, but that doesn''t make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it, or risk being considered ignorant by C and C++ programmers.
In C++ main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example:

#include

int main()
{
std::cout << "This program returns the integer value 0\n";
}

Note also that neither ISO C++ nor C99 allows you to leave the type out of a declation. That is, in contrast to C89 and ARM C++ ,"int" is not assumed where a type is missing in a declaration. Consequently:
#include

main() { /* ... */ }

is an error because the return type of main() is missing.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

Posted 11 December 2001 - 08:42 AM

Why don you use Dev C++? Ive found it much eisier to use.

### #10TotalCoder  Members

Posted 11 December 2001 - 08:55 AM

I''ll give it a try, do you have a link? If not, I''ll pull it down from Google. But thanks for the information, that is what I''m looking for, before Borland, all I new was LCC, GCC, Borland, and, for work, I use MS Visual C++.

But since I''m targeting novices and hobbyist I don''t want to include VC++ from the beginning because most non-students can''t afford it. But I''ll look into Dev C++, does it have a color syntaxing IDE? I hate coding in Notepad because I don''t remember half the keywords! MS Visual C++ has spoiled me and it looks as if it has hidden many important constructs from me as well such as int main() etc... Since coding in C++ and using MFC I haven''t seen a MAIN function in eons.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

### #11Null and Void  Members

Posted 11 December 2001 - 10:12 AM

I personally use void to indicate an empty parameter list in C++ too, I think it makes it more clear (maybe because I do a whole lot of C programming too?).
quote:
Original post by TotalCoder
I''ll give it a try, do you have a link?

Bloodshed.net.
quote:
Original post by TotalCoder
But I''ll look into Dev C++, does it have a color syntaxing IDE?

Yes. It''s a lot like MSVC.

[Resist Windows XP''s Invasive Production Activation Technology!]

### #12Arild Fines  Members

Posted 11 December 2001 - 10:24 AM

quote:
Original post by krez
you mean
int SomeFunc(void) { ... };

right?
why not? i thought that was good form...

I dont recommend it - ergo its not recommended.

Fantastic doctrines (like Christianity or Islam or Marxism) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

### #13Null and Void  Members

Posted 11 December 2001 - 10:49 AM

Although this is probably a typo caused by haste, you need to return 0 now that you have the return type of main as int.

[Resist Windows XP''s Invasive Production Activation Technology!]

### #14Arild Fines  Members

Posted 11 December 2001 - 11:12 AM

Null - nope. The standard explicitly states that if you exit main without returning a value, the effect will be that of returning 0.

(VC++ 6.0 doesnt work that way, tho)

Fantastic doctrines (like Christianity or Islam or Marxism) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

### #15Anonymous Poster_Anonymous Poster_*  Guests

Posted 11 December 2001 - 11:36 AM

quote:
Original post by Arild Fines
I dont recommend it - ergo its not recommended.

yes, i figured that out the first time you said "it''s not recommended"... but, what i meant to ask was: is there a reason for this, or is it a personal taste thing?

### #16Arild Fines  Members

Posted 11 December 2001 - 11:45 AM

Sure there is a reason for it: I dont do it this way, and everybody should do things exactly the same way I do them.

Fantastic doctrines (like Christianity or Islam or Marxism) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

### #17TotalCoder  Members

Posted 11 December 2001 - 12:19 PM

Thanks everyone for all your posts, critique, and recommendation. I appreciate everything that you have written. I have included everyone that has contributed to the tutorial in the additional credit section of the article, if any of you want your email or other names attached to it, let me know.

I''m working on the next tutorial which will combine input and outpout mostly cin and cout so that the reader can do some interactive stuff.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

### #18Gummo  Members

Posted 11 December 2001 - 03:03 PM

In your int main function, you should include "return 0;" before the closing brace.

### #19TotalCoder  Members

Posted 11 December 2001 - 03:53 PM

Should there be a return 0 statement? Here is a quote from the Bjarne Style FAQ I found on the web.

quote:

In C++ main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution...

The return value is impled and 0 is returned.

Sam
-----
TotalCoder
http://www.totalcoder.com
"Resources, tutorials, and articles for the novice, part-time, and hobbyist programmer"

### #20Arild Fines  Members

Posted 12 December 2001 - 02:14 AM

Bjarne is absolutely correct, as I have pointed out earlier in this thread. Read the standard regarding the main function, section 3.6.2, I think(something like that, anyway - I dont have it here right now).
The main problem is that VC++ gives you a warning when exiting main without an explicit return statement, and since VC++ is the compiler ''everyone'' uses, people think this is they way its supposed to be.

Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.