Learning C++

Hey everyone!
I am 14 years old and really like programming. I have experience in python, HTML, and javascript. I also have experience in 2D graphics for games. I don't think it will take me more than a week or two to learn the basics of C++ (as in loops, classes, variables, etc.) After that, does anyone have suggestions as to where I can go to learn to program 2D/3D graphics in c++ (which IDE's, tutorials, libraries, etc) , and other more complex things?

Hi! Kudos on wanting to expand your programming skills:) However, C++ has a lot of pitfalls python and javascript don't, and I *think* most people would agree it is a more difficult language to learn.

That being said, if you want to do 2d programming, SFML is an excellent library. Together with for example Box2D for physics you can make some really cool stuff:) For 3d you could go with Irrlicht or Ogre3d, both of which are 3d graphics engines for C++, but if you wanted to get into the nitty-gritty of it you should check out the NeHe tutorials on OpenGL!

Good luck!
Thanks for the advice! What exactly do you mean by pitfalls? Also I have been wondering the following for a long time: In most java/c++ related languages the main function/object is called main. I'm pretty sure its int main in c++. Is this optional (it being called main) or mandatory? If it is optional, how does the compiler know that that is the main function, and not just some other random function? Thx
alexyalcin wrote:
Is this optional (it being called main) or mandatory?

It's mandatory if you're writing a "hosted" application (that is, a program that will be executed by an operating system). The OS, to put it simple, will make a call to main() in order to start executing your code.

It is optional if you're writing a "freestanding" application (that is, an OS kernel, a boot loader, etc), where something other than an OS is going to choose where to start executing your code.
Last edited on
As for C++ pitfalls.

Memory Management.

In C++, unlike a lot of the higher level languages such as Java, you are responsible for allocating and unallocating memory. This is done with the new keyword and the delete keyword. After that, you must understand how pointers work. A pointer is like an address to a house, and a non-pointer variable is like the house itself. For a long time, I did not know how this would be used. Pointers are used to allow other parts of your code be passed a small amount of data (just a 32 bit or 64 bit pointer), so that the OS does not have to copy the entire amount of data that you have stored to a different location. Pointer can also be used to allow other functions change the data in the pointers.

Also, order of operations are important, especially in if statements.

One last thing that got me when I was a beginner, if (x = 0) return 0; will set x to 0 and then evaluate if it is not 0. This will always fail. Soon afterwards, I was able to figure out that you should use == to evaluate, rather than just and = sign. C++ does not mark it as an error, where Java would.
Last edited on
C++ does not mark it as an error, where Java would

because it isn't an error (as such) in C++.

I tend to write the same this like this:

if (0 == x)

because if i accidentally missed off one of the equals signs it would throw a compile error.

And in terms a memory management if you use smart pointers like:

you don't have to manually free up memory. it'll free it up itself when the ref count drops to zero. There are still pitfalls in c++ but not any many as there used to be.
You can learn C++ anywhere throughout the internet, and since you're sounding pretty confident of yourself (which is indeed a good thing) that you can easily grasp the C++ knowledge that you need, then looking up some random tutorials on youtube should do the job well. However, if you're serious about learning C++ and not just the 'basics' i suggest you buy a book or something, because C++ is not an easy language to learn and fully understand, i remember it took me well over 8 months to learn just the basics back when i was 14, i didn't have any previous programming experience at that time though, so it shouldn't take you as much time as it took me, but still, i honestly doubt that you can learn all the basics of the language within a week. Anyways what i'm really trying to say is learning C++ will not be as easy as you might think, you will have to read, work and experiment, you will be challenged at times but never overwhelmed trust me, you will have fun while learning.
Last edited on
Topic archived. No new replies allowed.