Jump to content
  • Advertisement
Sign in to follow this  
game of thought

Moving onto c++ from c

This topic is 1849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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).

Edited by phil_t

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites



- 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#. ;)

Share this post


Link to post
Share on other sites

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.

Edited by samoth

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!