views:

165

answers:

7

Hey SO

Im a Java programmer, with a little C knowledge who wants to get started with with C++ can someone recommend a good tutorial?

also any help with:

  • projects to learn with
  • recommended reading
  • what IDE ? I currently use NetBeans
  • general C++ advice
+1  A: 

The reading link that In silico provided is a good one to look at.

My biggest and most general pieces of advice would be to get familiar with the Boost libraries and familiarize yourself RAII (Resource Allocation is Initialization) and live by it!

I'm not a user of NetBeans, but if you like it and ther is a C++ plug-in, then that's probably what I would suggest you start with. No sense on creating yet another environment you're trying to learn on top of a new language if you don't have to. Having said that, I'm an Eclipse user and the C++ (CDT) plugin for it is pretty nice.

RC
thanks I have used a Eclipse a little as a team I worked with once insisted on everyone using the same IDE, it was ok but i'm used to netbeans. But if I don't get on il have a wonder over to eclipse ^_^
Gwilym
+5  A: 

Depends on your target platform, I use Visual Studio as an IDE.

The general rule of C++ as opposed to Java is that it contains a hell of a lot more freedom than Java, especially as regards to templates vs generics, the stack vs the heap, and the enforcement (or lack thereof) of object orientation and it's principles. For example, C++ provides the encapsulation-breaking friend statement, the const_cast, allocates objects on the stack and pointers can point to them, templates have infinitely more power than generics, etc.

The other main thing you will have to get used to is resource management. C++ does not provide a GC. You will need to familiarize yourself with RAII (resource acquisition is initialization) and how scope-based construction and destruction work to avoid resource leaks.

You will also need to brush up on the Standard Template Library (STL). The STL has a much more directed approach than the Java libraries- for example, the std::iostream class provides native methods to extract floats, strings, etc from the file, whereas in Java you need both a File and a Scanner, although it's scope is far more limited- no GUI or directory-based components, just for starters.

Oh, by the way, seriously, ditch your C knowledge. It'll hurt rather than help you.

DeadMG
Friends do not necessarily break encapsulation.http://www.parashift.com/c++-faq-lite/friends.html#faq-14.2
RC
That's not the point. The point is that Java removed it because it could break encapsulation. C++ didn't.
DeadMG
thanks that a whole bundle of useful knowledge
Gwilym
+1  A: 

Get a college textbook style C++ book like Deitel and Deitel. The hard part is to learning all the details of the language when you design a reusable library, but if you're just piecing together existing parts, it should not be too bad if you already know Java. There's a subtle difference between object declared as plain variable, its pointer, and its reference that you need to learn, along with resource management. Once you get the hang of the language, fill in the gaps using the classics like Stroustrup and Meyers.

As per IDE is concerned, you should try as many as possible including Visual Studio, X Code, Anjuta, and Eclipse and see what you like best. You should probably also learn ways to build without the IDE using Make (or SCons) and vi.

For the project, you should first stick to CUI since there's no standard implementation of the GUI unlike Java, but eventually you'd like to implement something like Tetris or matrix math library, which fits in nicely to OO. wxWidgets and Qt are cross platform, if you want to make it cross platform, but you should target whatever the platform that you're interested in.

eed3si9n
+1  A: 

.This book too is not in the link and I use it :

Object oriented programming in C++ by Robert Lafore , It assumes Zero background and It's pretty easy .

.For IDE Visual studio is commonly used among beginners like me :) .

.As for a good example you may try to create a class for "Complex Numbers" that has its own add, delete ,multiply and divide member functions . You will learn about encapsulation of data and functions inside that class and also operator overloading

ex :

int i1 = 5 ; 
int i2 = 6 ; 
int i3 ;
i3 = i1 + i2 ; //correct

complex c1.setreal(3) ;  //here you learn about member functions of the class
complex c1.setimg(5) ; 
complex c2.setreal(6) ; 
complex c2.setimg(8) ;  
complex c3 ;
c3 = c1 + c2 ;//wrong until you overload the operator + 
Ahmed
A: 

Some Suggestions for IDE's:

  • NetBeans (full version) - Works with gcc (not included). On Windows, gcc is available with Cygwin and MingW. Can be used to build Qt based applications (see Qt below). Available for Windows, Linux, and Solaris (maybe others).
  • Qt Creator - Includes the Qt framework allowing portability of GUI applications to multiple platforms. Can be used with gcc or MSVC (Windows only). Available for 32-bit Windows (can be compiled for 64 bit Windows with some difficulty), 32 or 64 bit Linux and Mac OS X.
  • MS Visual C++ 2010 Express - Free download which can be used to build 32 or 64 bit Windows applications. Can be used to build standard C++ applications. It also allows building Managed C++, but if you're going to do that, you're probably better off going with C# instead. Cross-platform GUI's can be built with the Qt framework.
  • Eclipse CDT - I haven't used this one but I've heard good things about it, and would be remiss not to at least mention it. I know it will build 32-bit Windows apps (not sure 64 bit ones) and there are versions for Linux (both 32 and 64 bt).
andand
What, no Vi/Emacs? :)
greyfade
Installed the C++ plugin and got it happy with Gcc see hwo it goes from there
Gwilym
@greyfade: Good one!
andand
Why the downvote?
andand
+3  A: 

good tutorial?

No tutorial recommendations, because tutorial most likely won't touch more complex language features. Get a book.

projects to learn with

Qt 4 once you're familiar with language, any project that uses STL/Templates/Qt. Boost source code might be worth learning from.

recommended reading

Any Bjarne Stroustrup's book about C++. Heavy reading, but good as a reference, a book on design patterns might be helpful as well.

what IDE ? I currently use NetBeans

Visual Studio Express on windows, jEdit/Kate/mcedit/vim/emacs on Linux.

general C++ advice

Learn how to use external build systems (cmake/scons/gnu make), how to work without IDE, how to work from command-line, and try to avoid non-standard compiler-specific features.

SigTerm
A: 

recommended reading

Effective C++ by Scott Meyers.

dan04