开发者

Tutorials for an experienced C# user to learn C++

Are there any good resources for learning C++ that a C# user could use, which don't require knowledge of C?

I have quite a good knowledge of C# via courses in my University's game development program (in a 300 level course right now) but now I need to use C++ for a project.

I would use a beginner tutorial but they are so hard for me to follow and learn the basic syntax because they start so slowly.

I found a few of tutoria开发者_StackOverflow中文版ls for switching from C++ to C#, but none in the other direction. I do have a little bit of Objective C practice from iPhone programming as well.


C++ is a very different thing to wrap your brain around. Especially when you come from the managed world. Things you take for granted in C# does not exist in C++.

Other than that i suggest doing a small intro project for the purpose of learning - i always found tutorials difficult because they are not real problems. My suggestion is to implement a small game/project to get things started and then solve the problems you run into as-you-go.


C# and C++ have deceptively similar syntax, but in reality they are very different languages. As GMan said, maybe it's best if you start from scratch. Taking shortcuts when learning C++ will bite you badly for sure, but anyway, here's a quick list of things to focus on in the beginning:

  • most important: C++ is native, lower level language and it is assuming you know what you are doing. The framework/runtime will not hold your hand and merely slap you if you mess up, weird stuff will happen instead and if you are lucky the OS will terminate you with great prejudice. Be prepared for that and be patient.

  • class and struct syntax - almost the same as C#, but still, there are minor differences

  • the big four: default constructor, copy-constructor, assignment operator and destructor of a class. C# lacks copy-construction and assignment, cloning is the closest thing there. In C# destructors are non-deterministic, might run on a different thread and are generally discouraged in favor of IDisposable; C++ destructors on the other hand are deterministic and very important.

  • stack vs heap allocation - to new or not to new - in C++ there are no value and reference types, no boxing and unboxing, the decision whether to allocate on the stack or on the heap is made per variable. You could have ints allocated on the heap and classes (objects) on the stack.

  • memory management and RAII - C++ lacks garbage collection, you should clean up your own trash. Be aware that there are smart pointers (in boost libraries and also in tr1) that will make memory management almost as easy as in C#

  • templates - don't go deep with templates, as a C++ beginner it's fairly safe to look at them as generics, that should be enough to let you use...

  • STL - know your framework

  • exceptions - if you use them, beware there's no finally in C++, all that work should be done in destructors (see RAII)


There are lots of resources titled C# for C++ programmers.

You can use them ;) You will come to know what are the things you are going to miss when you move from C# to C++.

C++ vs. C# - a Checklist from a C++ Programmers Point of View.

Learn some syntax first and then some STL. In a week you will feel comfortable.

But there is no need to start from scratch because C# borrows a lot from C++.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜