views:

361

answers:

9

At my university most of my classes have been in Java. I have also recently learned C# (and the Visual Studio environment) at a summer internship. Now I'm taking an Intro to Computer Graphics class and the grad student teaching the class prefers us to use C++ to access the OpenGL bindings via GLUT.

Does anyone have any good resources on how to make a good transition from Java/C# to C++? Obviously pointers are going to be a big issue, but any other things I should be looking out for? Any tutorials, guides, etc. would be very helpful!

Thanks!

+3  A: 

If you already know Java/C# I'd recommend going directly to C instead of C++. According to the website, GLUT has the same bindings for C as C++ so you should be all set. Anyways, the best way to learn C is to purchase and read a copy of "The C Programming Language" and sit down with your C compiler and get your stuff to run.

Kyle Cronin
+2  A: 

Effective C++ by Scott Meyers is a great book to help you learn C++. Gives you an overview of the language and introduces a lot of key concepts that you will use throughout the development of basically any C++ program.

Magic Hat
+7  A: 

Yeah, I got bit by the same bug. The university tended to lean on Java, and then allowed you to choose the language you wanted to work with during projects.

The best way is to just jump in. Start small, take baby steps, and just Google things that confuse you when you get there. Also find projects that have released their source code. See how they structure their programs. Basically, just tinker with concepts. There is plenty of information around the web.

Make it fun and grab a C++ game development book so it doesn't become mind numbing too quickly.

Here's some places that I found useful while learning

http://www.cprogramming.com/

http://www.wikipedia.com

http://www.cplusplus.com/

David McGraw
+1  A: 

Effective C++ by Scott Meyers is a great book to help you learn C++. Gives you an overview of the language and introduces a lot of key concepts that you will use throughout the development of basically any C++ program.

I love this book in all 3 editions, and it was one of the books in a class I had as a Senior at UT, but it's just not a starting book. You can become comfortable in C++ with a lot less, though you certainly won't be one with the compiler until you have read Meyer's work.

I don't know if it's still in print but I found Navigating C++ usefull, but I was also very comfortable with pointers from Pascal. Err of course I am forgetting that 15 years ago you had to learn what OOP was, now it's a little more assumed. So perhaps Meyer's is not out of line. Thoughts?

Dan Blair
+2  A: 

Wikipedia has an article on comparisons between Java and C++.

You don't have to worry about checked exceptions in C++, but you do need to know about const correctness.

Mark Cidade
+1  A: 

There are two main differences: the syntax, and memory management.

In C++ you have pointers, which are more powerful (or less powerful depending on your interpretation of power) object references, which you already know about from Java.

In Java you might do this:

Thing mything = new Thing(); // mything is an object reference
mything.method();

In C++ you would do this:

Thing * mything = new Thing(); // mything is an object pointer
mything->method();
delete mything;

The syntactical difference is obvious: '->' instead of '.' when calling an object method from a pointer to an object. In C++, you have to free the memory explicitly when you are done with an object. At the end of the day you are doing the same thing in C++ and Java, instantiating objects and calling methods, putting useless semicolons at the end of every line, etc. Is it any wonder that Python is becoming so popular?:

mything = Thing() # mything is whatever I want it to be
mything.method()

Skimming through any half decent C++ text will help you fill in the rest of the details.

postfuturist
+2  A: 

I also thoroughly recommend Bruce Eckel's Thinking in C++. A fantastic book for already experienced programmers that want to get into the C++ mindset.

He is kind enough to make electronic versions of his books available for free.

Cheekysoft
+2  A: 

I strongly recommend that anyone learning C++ reads Stroustrups "The C++ Programming Language." Meyers and Eckel have great stuff, but nothing beats learning from the guy who decided what the language should be and how he intended for it to be used.

Kristopher Johnson
+2  A: 

I had the exact same issue. The only book I was able to find was "Pro Visual C++ 2005 for C# Developers" by Dean C. Wills. It's a good read with excellent examples, and I think the angle from which the book comes is probably what you're looking for.

adeel825