Moving onto c++ from c

Started by
5 comments, last by Serapth 10 years, 10 months ago
I have learned c for roughly 3 months and i believe i have a good grasp on most stuff(save char pointers but i am working on it). I now want to move onto c++ because of a few reasons:

- better dynamic memory allocation
- boolean(better than unsigned char IMO)
- classes
- the ability to not have to use pointers as much
- better STD lib

Etc.


Now i have bought a c++ textbook and i have read the first few chapters and it seems identical to c. Since i am new to c/c++ i dont really want to miss anything that may be important but i am pushed for time.

Which topics should i read and practice and which ones can be ignored or are identical to c?
Advertisement

Off the top of my head:

- constructors and destructors

- member visibility (public, private, protected), which ties into information hiding.

- virtual methods and class inheritance

- RAII (resource acquisition is initialization)... not specifically C++, but a good concept to be familiar with, and it will lead into smart pointers

- references

- templates (more advanced topic, but you should have some familiarity with them since they are used in smart pointers and containers).

the ability to not have to use pointers as much

Make sure you got good grasp on arrays and pointers.You should not skip those!

I am fine with pointers, i would just like to rely in them less that i would in c. Which from what i hear is with c++.

In C++, you use alot of pointers still. Though with modern C++ styles, these are more likely to be smart pointers like std::shared_ptr, std::weak_ptr, and std::unique_ptr. Even so, you still use the occasional raw pointer, and you use loads of references as well (which can be thought of as simplified and safer pointers)

Thanks everyone



- better dynamic memory allocation
- boolean(better than unsigned char IMO)
- classes
- the ability to not have to use pointers as much
- better STD lib

Etc.

It's kinda funny because every single thing on that list would be true of moving from C++ to C#. ;)

You should probably not think of C++ as a "better C" because that is not what it is. C++ looks somewhat similar and even does borrow some things from C (sadly, one has to say -- while C as such isn't a bad language, this sure doesn't make C++ better -- I prefer doing one thing or the other, you just shouldn't borrow things that somehow don't fit in), but it's a completely different language.

A lot of things that are allowable or even idioms in C will make a C++ programmer throw up (or, throw things at you). Try not to mix the two, a C programmer doing "some C++" is usually a terrible C++ programmer (talking out of experience).

The probably most important (and, at the same time, most annoying at first sight) things that you'll have to learn and adapt to quickly is much stricter typing and the fact that there exist exceptions (and your programs must be written in a way so no evil things happen in their presence). That, constructors and destructors, and function overloading, including overloaded operators.

If you can, you should try to learn C++11 right away, since it is again a completely different language than "old C++" (or nearly so). Compiler support (for the most part) is readily available, and the features of C++11 will make your life a lot happier.

This topic is closed to new replies.

Advertisement