Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Learning C++

Credits go to Andrei Ellman, clovekx, Evert, Gideon Weems, HoHo, Kris Allen, lucaz, Myrdos, Rash, Soga, spellcaster, Thomas Fjellstrom, Trezker, and X-G for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
Learning C++
gnolam
Member #2,030
March 2002
avatar

As an attempt to get back my motivation, I thought I'd broaden my horizons a bit. I think I've learned as much C as I'm ever going to, so I thought I'd join the dark side and learn the evil that is C++ ;)

Most tutorials and books I have glanced at seem to fall into one of two categories:

  • Aimed at people who have never programmed before in their life.

</li>

So... do you guys know any good resources for learning C++? Preferrably from a C perspective.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

spellcaster
Member #1,493
September 2001
avatar

There's not much to know, really. From the language point of view, that is.
Structs can fave functions. functions can be virtual. Classes are structs that default to private access. You can use inheritance...
So basically, what you should do is get used to constructors and destructors, esp. initilaizer lists.
Then you should check out what "virtual" does for you.

Next step would be templates.
Now you should take a look at the many neat libs that are available for C++.

That's it. All the other stuff explains how to usee C++, as in "OOP with C++".

What I'd suggest is that you read the C++ FAQs and then get the "Design Patterns" book. The C++ FAQ should answer most questions, and with the FAQ next to you, you should be able to switch from C to C++.
"Design Patterns" are nice, object oriented approaches to common problems.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Kris Allen
Member #4,639
May 2004
avatar

I can tell you a book not to get: SAMS Learn C++ in 21 days. Absolute crap... when they're not teaching you to use "std::cout" when just "cout" is fine (that's what "using namespace whatever" is for, after all), they're shoving 200-line examples down your neck that just bore you.

They say anything by O'Reilly is good, I'm sure they've got a C++ book in shops

- Kris

Myrdos
Member #1,772
December 2001

I might be tempted to start using#include <string>instead of#include <string.h>

A good reference for strings, vectors and other useful C++ classes:
http://www.cppreference.com/

Also, next step would be to try using #include <iostream> instead of #include <stdio.h>

A good reference for I/O:
www.cplusplus.com (Go to standard libraries and then iostream library)

I think you'll find that these simple changes will, IMO, make your code more readable and give a basic idea of how C++ classes work.

__________________________________________________

Evert
Member #794
November 2000
avatar

Quote:

I can tell you a book not to get: SAMS Learn C++ in 21 days.

Well, the title is a giveaway ;)

I've heard mixed things about Stroustrup's book on C++: some people like it, some people say it's horrible. I have no real opinion on it, never having read the book. My only reference for C++ are the two or three paragraphs at the end of my C book, which is rather dated.

Gideon Weems
Member #3,925
October 2003

I must have at least a dozen C++ books, and the best one is entitled The C++ Black Book, published by Corollis.

But, c'mon! You've got the best forum in the world to help you out--books schmooks. (Besides, I don't quite understand the big deal people try to make between C/C++. They're the same language.)

HoHo
Member #4,534
April 2004
avatar

Why haven't anyone suggested Bruce Eckel's books? Thats how I learnt c/c++.

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

Rash
Member #2,374
May 2002
avatar

Stroustrup's book is meant as a reference guide.

There's the often-heard advice for existing programmers to get "Accelerated C++" by Koenig and Moo.
Then, there's this.

X-G
Member #856
December 2000
avatar

The one I read a few years ago was Objektorienterad programmering med C++, available from Studentlitteratur. I haven't read many other books though, so I can't say if it was good or not.

It's not so much about learning C++ as about learning how to do proper object oriented programming...

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Trezker
Member #1,739
December 2001
avatar

They told us to buy c++ Direkt in my uni...
It's pretty good, but it's from a newbie perspective.

You could read Wrox press c++ tutorial, I found it very nice.

Thomas Fjellstrom
Member #476
June 2000
avatar

I read some crappy C++ books years ago.. and promptly forgot anything I learned. Later I learned general OO from other languages and just applied it to C/C++. Syntax is just syntax, its the new concepts that you need to learn and apply.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

spellcaster
Member #1,493
September 2001
avatar

I leaerned C++ from Scott Meyers books.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

clovekx
Member #3,479
April 2003
avatar

lucaz
Member #4,194
January 2004

Banana, check out Stroustrup's book.

EDIT: ...and Bjarne's site too.

Andrei Ellman
Member #3,434
April 2003

One place to start would be the O'Reilly and Associates Inc. Book "C++: The Core Language" ( ISBN 1-56592-116-X ). It is a book about C++ specially aimed at C programmers wanting to switch to C++. As far as C++ books go, it's short (only 200 pages), but it assumes you know C. Also, it only discusses the basics of C++ leaving out the details (but it tells you about the concepts of C++ and how to use them). To fill yourself in, I suggest you either get (buy/borrow/burgle) one of those long C++ reference-books or find a C++ reference website to look up what you still don't know.

One of the things about C++ is that it comes in many layers (the most basic layer basically being C with stricter type-checking). You don't have to use all of it's features (eg. it is possible to make use of classes and inheritance while completely ignoring templates). You can learn just the layers you feel comfy with and use those, but if you chose that method of using C++, you will inevitably come accross someone else's C++ that uses these features you haven't learned yet.

Learning C++ is like an odessy - There's a lot to learn, but it can be broken down into smaller chunks which can be learned one chunk at a time, but there is always something lurking round each corner.

And then there's the C++ Standard Template Library (STL) and object-oriented design to get your teeth into.

AE++.

--
Don't let the illegitimates turn you into carbon.

Thomas Fjellstrom
Member #476
June 2000
avatar

If you think about it, all the while you're learning and using C, you are learning C++.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Soga
Member #4,589
May 2004

I use SAMS for reference.

gnolam
Member #2,030
March 2002
avatar

Lots of books and few online references, but thanks all :)

Gideon Weems said:

Besides, I don't quite understand the big deal people try to make between C/C++. They're the same language.

You mean... besides the different foci, data types and interpretations of identical code snippets? ;)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Derezo
Member #1,666
April 2001
avatar

C/C++ are very similar. I migrated without any issues. I used some references to learn about inheritance and such, but I don't usually use those practices anyway. The only thing that makes a huge difference are the additional libraries, such as STL.

Spellcaster said the important difference : Stucts can now have functions, and you can protect their members.
Constructors/Destructors are pretty simple concepts. Runs a function when the object is created, and runs another when it leaves the scope. ie.

1class MyClass
2 {
3 private:
4 int val;
5 OtherClass *ptr;
6 
7 public:
8 MyClass() // constructor
9 {
10 val = 1;
11 ptr = new OtherClass;
12 }
13 
14 ~MyClass() // destructor
15 {
16 val = 0;
17 delete ptr;
18 }
19 };

Weeee...

"He who controls the stuffing controls the Universe"

lucaz
Member #4,194
January 2004

When I started to read C++ I thought, "hey, this is the same with functions in structs and some other stuff".
But when time passed, I discovered the way to program in C++ is VERY different from C.
Most of people program in C and use some C++ stuff.
But they are very different languages.

Hard Rock
Member #1,547
September 2001
avatar

The book i bought was C++ the complete reference. Its very well written and extrememly helpful. The first chapter is basically an introduction to C, and then it goes over all C++ new features and how exactly they work. It devotes a chapter to each C++ feature and compares it C, as well as going over changes between versions and shows examples of each feature. Finally the last chapter is just a reference you can use, which is great too.

_________________________________________________
Hard Rock
[ Stars Dev Company ][ Twitter ][Global Warming: ARA My TINS 07 Entry][Pong Ultra Website][GifAllegS Ver 1.07]
"Well there's also coolwebsearch but we'll let that be an IE exclusive feature" - arielb on the New Browser Plugins "What's better, HTML or Variables?"

juvinious
Member #5,145
October 2004
avatar

I'd say Herbert Schildt has made some good C++ books that are worth checking out.

__________________________________________
Paintown

Kanzure
Member #3,669
July 2003
avatar

Gillius has some good tutorials on his site. :)

Chris Katko
Member #1,881
January 2002
avatar

Quote:

I can tell you a book not to get: SAMS Learn C++ in 21 days.

Hey! I learned what C++ I know from that! Oh wait... maybe that's why I've had to relearn C++... ;)

Seriously, their example of linked-arrays is insanely long (5+ pages!) and over-complex.

Quote:

Well, the title is a giveaway ;)

It is?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

X-G
Member #856
December 2000
avatar

Quote:

It is?

Anything that claims to be able to teach you such a relatively complex thing as a programming language (and likely a whole new programming paradigm to boot!) in a mere 21 days is either lying or horribly mistaken. Not even the best of teachers can pull off that stunt. If the authors can't realize that, chances are they didn't do a very good job with the book either...

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

 1   2 


Go to: