开发者

Learning C++ right?

开发者 https://www.devze.com 2022-12-16 19:51 出处:网络
Since I have been mostly using script languages in the past time but now want to go to the \"high-performance\" level I decided to learn C++ some time ago.

Since I have been mostly using script languages in the past time but now want to go to the "high-performance" level I decided to learn C++ some time ago.

I开发者_C百科 looked at some "beginner" tutorials and bought an O'reilly C++ pocket reference book (it's really helpful). My problem is that I now know all the basics but I'm not good enought to program a more complicated game, for example, yet.

  • Do I have to get one of those thick C++ books for further learning?
  • I'm going to use C++ on Windows mainly. What APIs beside Win32 are important for me?
  • My goal would be to write a small interpreter for a programming language I've though of - I managed that in several scripting languages already, what API/Library knowledge do I need in C++ to write one?


  1. You don't need a thick book - you need a good one. Get Accelerated C++, written by Koenig & Moo, two of the original C++ development team.

  2. Depends what you want to do.

  3. You don't need anything - you can write a perfectly good interpreter or compiler using just the C++ Standard library. See this SO question for lots of info in this area.


Learn with books. C++ is a complex language. My suggestion is to first go with a rather quick introduction and general overview of the major programming paradigms that C++ supports: OOP and generic programming: Accelerated C++.

When you finish this book, you can go with the two volumes of Bruce Eckel's Thinking in C++ which are very detailed.

For UI programming, the best C++ toolkit is Qt, and it is multiplaform-ready. You can read "C++ GUI Programming With Qt4" (the first edition is free to download, just google it). If you want to stick with C++/Windows API, learn the Windows Template Library, altough it may be a bit hard due to lack of official documentation (altough there are good tutorials on the net). WTL is the way to go to create very small, lightweight applications (Qt DLLs on the other side, need a few MBs each).


I have always found that learning a language from a book is pretty difficult and that after you know the basics you should begin to program. So instead of picking up a thick manual I would check out something like http://www.cprogramming.com/tutorial.html#advanced or just google for c++ tutorial and something that you would like to try to make.


  • A good (and) thin book to get started in C++ is Accelerated C++ by Koenig and Moo.
  • I mainly do programming under Linux, but I hear a lot of bad things about MFC, so I'd try to find a different GUI library.
  • Once you get up to speed with some of the more complicated parts of C++ syntax, have a look at the Boost.Spirit libraries for parser generation. The various Boost libraries provide some very useful extensions to the Standard Library.


Honestly, In learning C++ i never picked up a book (no flaming please). The best advice i can give is to go to this page and go through the tutorial. It covers the majority of the C++ language (read: most commonly used features) and keeps it as simple as possible. As far as APIs that are important... well that is a matter of preference. No one toolkit/api has really "won", but Qt, GTK-- (gtkmm), and wxWidgets are all big players. And besides GUIs, you'll probably want to learn either the raw winsock2 and threading APIs OR the boost library's threading and network interfaces. I do agree that MFC is dying, and for windows-only development C# is taking an increasingly large role (even on linux/mono C# is starting to catch on... slowly).

Also, the best way to learn a language is to code. So don't just read a whole ton- without practical experience you're never going to learn the language. Ask questions, answer those you can, and write tutorials- for yourself if nobody else. Writing down what you've learned is a great reference, and the process of straightening everything out in your head to write it down in a fashion that another person can understand it alone is a great way to reinforce concepts. In a strange, but seemingly backwards, way I found the best way I learn programming is by helping other people with their questions.

@Neil- i disagree that online tutorials are "flat out wrong". If anything, the style they teach you might be geared towards readability rather than optimization- which in-my-not-so-humble-opinion is an advantage. In my limited experience I've found cplusplus.com a go-to reference for pretty much everything.

Specifically, to answer your questions: 1. No thick book needed. I've heard that the thinner ones can be useful as a quick reference, though.

  1. It's completely subjective and depends on your goal. Boost's network and multithreading libraries are probably a good start.

  2. between std::string, std::stringstream, and getline(std::istream&, std::string&) you should be pretty good. C++ comes with a whole ton of built-in functionality yet isn't too bloated/huge/impossible to learn. Take advantage of it. All of the parsing is built in already.


Please, for Pete's sake, don't use directly use the Win32 API. You'll be painting yourself in the Microsoft corner. There are plenty of cross-platform libraries out there you can use instead:

  • Standard C++ library: strings, file i/o, containers, algorithms
  • Boost for the everyday stuff they left out of the standard library: parsing, networking, threading, smart pointers, memory pools, date/time, matrices, etc... Boost libraries are peer-reviewed before being accepted and are high-quality. Boost is the breeding ground for libraries that eventually become part of the next C++ standard.
  • GUI Toolkits: Qt and wxWidgets are very mature and widely used. There are many more.


For C++ on windows, definitely learn Microsoft Foundation Classes (MFC). Without MFC, you have to implmenet all of the windows API stuff yourself, which is more C than C++ and can be quite a pain.

You also may want to get, learn, and use the boost C++ libraries. They aren't windows specific, but they are a great resource for anyone.


I highly recommend Stroustrup's Intro C++ book. It covers C++ and STL in a very approachable way.

After that you might consider looking into books on Qt, a multi-platform GUI toolkit, or WTL or MFC for Windows. You could do .NET + C++, but that would be a lot to learn. In my experience with Qt and MFC, books have not helped much. Tampering with sample apps, building small apps just to test out one kind of feature, and poking around the docs was the only way I could get my head around either library. The books I had tended to simply gloss over too much--they were not worth the money.

0

精彩评论

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