• ### Announcements

GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Followers 0

# Moving from Java to c++

## 21 posts in this topic

I recently decided to start learning a second language now that I'm quite comfortable with Java. I'm just looking for a few opinions on which ide to use, what I'm looking for is something that's free, or 'free,' that is well documented/used in a lot of tutorials.

I feel like the ide will have a bigger impact when learning c++ than it did when I was learning Java as I'll be using features other than the text editor much more often(correct me if I'm wrong), so I'm looking for something that is widely used and therefore easier to google anything I might need to find out about it.

I'm familiar with eclipse using Java, I'm not sure how good it is for c++ I know it's an option though. Just from googling around I see a lot of people who love VS but also a small subset of people who absolutely hate it. Also I don't know how hard it'd be to get without spending hundreds of dollars/how good the express edition is.

What would you recommend for someone who wants to learn c++ and eventually use it for much more complex programming?

for the record; I love intellisense, and I'm using windows 7 on a reasonably fast computer

EDIT:
this is my reply I posted further down, I just wanted to include it here so more people see it because I'd like to get some more feedback on it but it doesn't really warrant a new thread.

Thanks for all the great replies everyone! I think I'm going with Visual studio 2012 express(is there any reason that I might use 2010 instead?). I tried a few tutorials already just using visual c++ express cause apparently I already had it, but it always got build errors. just from simple hello world programs. I'm assuming It's something to do with my setup because i tried several tutorials copying the code exactly and they all got the same error. even the default hello world program errored. hopefully I wont have that issue in VS
[quote name='Stroppy Katamari' timestamp='1351560750' post='4995244']
I would recommend not using an IDE at first, actually. Using a toolchain of separate tools (initially this can be just text editor and compiler, with build control, memory analyzer, static analyzer, debugger added into the mix later one by one) lets you learn faster what is going on. Also, while you have a small amount of code, like just a couple of thousand or ten thousand lines, I don't see an IDE actually doing anything for you over separate tools.
[/quote]
Hmmm. that actually sounds like a good idea, my main goal here is to learn everything thoroughly and properly from the beginning so I can be a good c++ programmer soon. I think forcing myself to do that will help me learn things that I'd usually just happily ignore and let my IDE do it for me. How important and how hard is learning all that? Anyone else think this is a good idea?
Also while I'm here, should I start with c++ 11? I know nothing about the different versions, is it backwards compatible? is it or will it be the standard soon? which version do you recommend I start with and why? The only concern I might have about that is that its new and might not be as well documented, I love have a wealth of resources when learning something new and complicated like c++.
Anyone have any other general suggestions for learning resources or tips? I wanna learn this as thoroughly and as well as possible but I'm also eager to get my hands dirty with some real programming as soon as I can Edited by Moe091
0

##### Share on other sites
[quote name='Moe091' timestamp='1351540968' post='4995144']
I'm just looking for a few opinions on which ide to use, what I'm looking for is something that's free, or 'free,' that is well documented/used in a lot of tutorials.
[/quote]
The most popular free IDEs for C++ are probably, in no particular order, Visual C++ Express, Code::Blocks and Qt Creator.

[quote]
I feel like the ide will have a bigger impact when learning c++ than it did when I was learning Java
[/quote]
Perhaps. For Java, an IDE as pretty-much mandatory though, as the build process is difficult to manage without one. In C++, it's doable (though non-trivial) without using an IDE.

[quote]I'm familiar with eclipse using Java, I'm not sure how good it is for c++ I know it's an option though.[/quote]
I only tried the Eclipse CDT plugin ~5 years ago. It was awful then (too slow to be useful), but it might have improved by now. You could of course take a look at a recent version if you're sufficiently attached to eclipse.

[quote]Just from googling around I see a lot of people who love VS but also a small subset of people who absolutely hate it.[/quote]
I'm one of the people that hate it (though I like the Visual C++ toolchain). Vim has spoilt me.

[quote]Also I don't know how hard it'd be to get without spending hundreds of dollars/how good the express edition is.[/quote]
The express edition is probably fine. It certainly won't hurt for starters.

I will say though, that regardless of the IDE you pick, it's absolutely essential, IMHO, that you get to grips with the C++ compilation model early on. Once you understand this, you'll be able to fix your own problems easily, regardless of which IDE you pick.
2

##### Share on other sites
The new vs2012 express is VERY GOOD. Also Eclipse CDT is pretty good, actually the most feature complete IDE in existence, however can be a bitch to setup and get working. And can be slow.

QT Creator is the best cross platform IDE in existence.

VS2012 is the best windows IDE with QTCreator the close second.

Code::blocks is ok but lacks many features, such as real syntax highlighting, and hasn't been update for 2 years.
1

##### Share on other sites
[quote name='Moe091' timestamp='1351540968' post='4995144']
What would you recommend for someone who wants to learn c++ and eventually use it for much more complex programming?
[/quote]I would recommend not using an IDE at first, actually. Using a toolchain of separate tools (initially this can be just text editor and compiler, with build control, memory analyzer, static analyzer, debugger added into the mix later one by one) lets you learn faster what is going on. Also, while you have a small amount of code, like just a couple of thousand or ten thousand lines, I don't see an IDE actually doing anything for you over separate tools.
1

##### Share on other sites
Brace yourself for the horrors of memory management. That is all.
However in all seriousness, some pointers:

1) C++ Is Unforgiving. Your code's errors can be extremely weird.
Example:
I had my Breakout game. In debug mode everything worked fine, however in release mode whenever the cursor crossed a certain Y position on the screen the game would just close. I eventually found out that I had an undefined Boolean value that I was referencing in a Class. The bug was annoying because it was working fine on my machine, which made pinpointing the error extremely annoying. And of course, the IDE in debug mode didn't give me the error (Or even a warning message).

2) Memory Management Tips
First Tip: Delete dynamically allocated memory as soon as possible. Whenever you do, set the pointer to null.
Also, try to use the new operator as little as possible. Using auto-pointers is fine, and you generally don't need the normal new and delete operators.

Also, I use Visual Studio, however there are many good IDE's. The debugger in Visual Studio is amazing.
I've used Code::Blocks. It doesn't have precompiled headers and the library support is good, however a lot of the auto-linking libraries don't work (SFML 1.6, as of now, doesn't work correctly).

It really doesn't matter which IDE you use. Just try them all out and see which one you like.
2

##### Share on other sites
[quote name='superman3275' timestamp='1351562252' post='4995256']
And of course, the IDE in debug mode didn't give me the error (Or even a warning message).
[/quote]
The reason is because it is not a warning or error to the language. Also this is a big reason that you should use initializer lists in all constructors to initialize the class members, or in the rare case that you don't (say in a vector4 or matrix44) you need to be careful never to use it until it has been assigned a value. Note the reason it works fine in debug mode is that values will be initialized whereas in release mode they are not.

[quote name='superman3275' timestamp='1351562252' post='4995256']
First Tip: Delete dynamically allocated memory as soon as possible. Whenever you do, set the pointer to null.
[/quote]
I disagree with both. It is actually much better to reuse dynamically allocated memory at runtime than to delete and reacquire. I would only delete when it is no longer needed. Although this is really a non-issue if you are using C++11 due to having std::unique_ptr, std::shared_ptr, and std::weak_ptr.

Regarding setting the pointer to null after deletion this is something I [b]absolutely [/b]disagree with and is just inviting bugs to linger in your codebase. By setting to null you won't catch any double delete errors, etc which would be found and handled easily by attempted to delete something that has already been deallocated. Edited by joew
2

##### Share on other sites
[quote name='joew' timestamp='1351563540' post='4995261']
Regarding setting the pointer to null after deletion this is something I [b]absolutely [/b]disagree with and is just inviting bugs to linger in your codebase. By setting to null you won't catch any double delete errors, etc which would be found and handled easily by attempted to delete something that has already been deallocated.
[/quote]

This is something that is important in C so many C programmers carry this habit over to C++.
0

##### Share on other sites
As you're coming from eclipse i would recommend Code::Blocks and Netbeans. Eclipse CDT is ok,
but I don't like it's gdb integration. It doesn't keep the hook properly, and that makes threading even more of a pain.
Both Netbeans and Code::Blocks are fairly lightweight. VS is great too, but for small projects like mine, VS just seems too heavy.
1

##### Share on other sites
Thanks for all the great replies everyone! I think I'm going with Visual studio 2012 express(is there any reason that I might use 2010 instead?). I tried a few tutorials already just using visual c++ express cause apparently I already had it, but it always got build errors. just from simple hello world programs. I'm assuming It's something to do with my setup because i tried several tutorials copying the code exactly and they all got the same error. even the default hello world program errored. hopefully I wont have that issue in VS

[quote name='Stroppy Katamari' timestamp='1351560750' post='4995244']
I would recommend not using an IDE at first, actually. Using a toolchain of separate tools (initially this can be just text editor and compiler, with build control, memory analyzer, static analyzer, debugger added into the mix later one by one) lets you learn faster what is going on. Also, while you have a small amount of code, like just a couple of thousand or ten thousand lines, I don't see an IDE actually doing anything for you over separate tools.
[/quote]

Hmmm. that actually sounds like a good idea, my main goal here is to learn everything thoroughly and properly from the beginning so I can be a good c++ programmer soon. I think forcing myself to do that will help me learn things that I'd usually just happily ignore and let my IDE do it for me. How important and how hard is learning all that? Anyone else think this is a good idea?

Also while I'm here, should I start with c++ 11? I know nothing about the different versions, is it backwards compatible? is it or will it be the standard soon? which version do you recommend I start with and why? The only concern I might have about that is that its new and might not be as well documented, I love have a wealth of resources when learning something new and complicated like c++.

Anyone have any other general suggestions for learning resources or tips? I wanna learn this as thoroughly and as well as possible but I'm also eager to get my hands dirty with some real programming as soon as I can
0

##### Share on other sites
[quote name='Moe091' timestamp='1351614913' post='4995474']

Hmmm. that actually sounds like a good idea, my main goal here is to learn everything thoroughly and properly from the beginning so I can be a good c++ programmer soon. I think forcing myself to do that will help me learn things that I'd usually just happily ignore and let my IDE do it for me. How important and how hard is learning all that? Anyone else think this is a good idea?
[/quote]

A command-line compiler is a great tool to learn. You will use it at some point in your career, and I'd recommend using that over an IDE at this point in time. IDE like VS can spout out error because of IDE config errors, not your code. This can confuse beginners a lot, thinking that their code is wrong while in fact, the IDE is messed up.

[quote]
Also while I'm here, should I start with c++ 11? I know nothing about the different versions, is it backwards compatible? is it or will it be the standard soon? which version do you recommend I start with and why? The only concern I might have about that is that its new and might not be as well documented, I love have a wealth of resources when learning something new and complicated like c++.
[/quote]

I don't know much about C++ 11, but last time I tried to use it, the compilers have yet fully support all the features of C++ 11. You will get different results depending on which compiler/IDE you use (GNU, VS). I would suggest that you stay away from it for now. It's an extension of the language, not a whole redesign, so you won't miss a thing.

[quote]
Anyone have any other general suggestions for learning resources or tips? I wanna learn this as thoroughly and as well as possible but I'm also eager to get my hands dirty with some real programming as soon as I can
[/quote]

I would focus on pointers, ctors, and dtors, as that's one of the main differences between Java and C++. When objects are allocated/deallocated in C++ is a whole different thing.
1

##### Share on other sites
[quote name='Moe091' timestamp='1351614913' post='4995474']
Also while I'm here, should I start with c++ 11? I know nothing about the different versions, is it backwards compatible? is it or will it be the standard soon? which version do you recommend I start with and why? The only concern I might have about that is that its new and might not be as well documented, I love have a wealth of resources when learning something new and complicated like c++.[/quote]It's "backwards compatible" in the sense that pretty much all older C++ code is valid C++11 code as well.
I would say yes, use C++11 features as much as your compiler of choice supports. It makes the code more readable, more compact and more efficient. GCC as well as Microsoft's compiler both have decently wide support and are constantly getting more. Clang is getting there too, but slower.
0

##### Share on other sites
ah I see, I was confused about c++ 11 thanks for clearing that up. I'll definitely just stick to 'regular' c++. I'm gonna download a compiler and just get started with that and notepad, does it matter much which compiler I use? Which would you guys recommend I'm just looking for something popular and standard. I didnt look into compilers much yet so sorry if that's a stupid question
0

##### Share on other sites
I like g++, but I am not sure how people normally use it under Windows (I have used it under Linux, Solaris and Mac OS/X).

* Don't do your own dynamic memory allocation: Use local variables and standard containers instead.
* If you really need dynamic memory allocation, use a smart pointer like std::shared_ptr.

If you feel tempted to use new' (which I know is a common tendency in Java programmers), resist your urge. You probably don't need it. If you can't figure out how to avoid it, post here and we'll probably be able to help.
0

##### Share on other sites
[quote name='alvaro' timestamp='1351629566' post='4995566']
I like g++, but I am not sure how people normally use it under Windows (I have used it under Linux, Solaris and Mac OS/X).

* Don't do your own dynamic memory allocation: Use local variables and standard containers instead.
* If you really need dynamic memory allocation, use a smart pointer like std::shared_ptr.

If you feel tempted to use new' (which I know is a common tendency in Java programmers), resist your urge. You probably don't need it. If you can't figure out how to avoid it, post here and we'll probably be able to help.
[/quote]

I'm sorry alvaro, my fat finger clicked on "down" arrow rather than "up" for your reputation points.
0

##### Share on other sites
I can tell this is gonna be fun already lol, it is surprisingly hard to google how to use c++ without a compiler. I tried winging it, I wrote a hello world in notepad and saved it as hello.cpp, navigated to the directory in command prompt and typed the command i finally found on google (c++ hello.cpp -o hello.exe) and I get an error saying 'c++' isn't a recognized command, so I'm assuming I have some more setup to do with my compiler(using the c++ compiler i downloaded with the microsoft sdk) in order for it to recognize the command. Can anyone help me or tell me what to google, I'm having trouble getting results related to my problem, just a bunch of stackexchanges about much more complicated questions than mine, ill be searching in the meantime.

EDIT: forget all my edits, I found the path to the VC compiler by running the VC command prompt, it's the default path for it.

Thanks again for all the help everybody

[quote name='alvaro' timestamp='1351629566' post='4995566']
I like g++, but I am not sure how people normally use it under Windows (I have used it under Linux, Solaris and Mac OS/X).

* Don't do your own dynamic memory allocation: Use local variables and standard containers instead.
* If you really need dynamic memory allocation, use a smart pointer like std::shared_ptr.

If you feel tempted to use `new' (which I know is a common tendency in Java programmers), resist your urge. You probably don't need it. If you can't figure out how to avoid it, post here and we'll probably be able to help.
[/quote]

thanks, I probably would have been using 'new' like crazy haha. These are the kind of tips I need Edited by Moe091
0

##### Share on other sites
First, I reiterate you'll definitely want to use C++11, even more so if you want to keep things 'regular'. If you try to keep your code conforming to the ancient C++98 standard, you'll need to use much more nonstandard libraries like Boost to accomplish basic things that in C++11 are in the standard library, and there's really no reason to do that.

The tools you get in MinGW are the most standard, best documented stuff you can find. Initially you just need to use the gcc compiler, but you'll also have the gdb debugger and make build tool waiting for you for later.
With gcc installed, you'll want to use
g++ -Wall -Wextra -std=c++11 -o hello.exe hello.cpp
to compile your Hello World. If the gcc is slightly older version, you'll need to use -std=c++0x instead of -std=c++11.

As for editors, Notepad is terrible. At the least, use Notepad++ or equivalent. The heavy hitters, Vim (my favorite) and Emacs are great but take some learning to use. Sublime Text is both easy and powerful, but is only free for evaluation, and continued use requires buying a license. The license is cheap, though. Edited by Stroppy Katamari
1

##### Share on other sites
I recommend, assuming you're on Windows, NetBeans/C++ on MinGW. Eclipse/CDT is more professional, but NetBeans is just [b]friendlier[/b] for beginners.
MinGW is the Windows implementation of GCC. You can get vanilla MinGW or The Dragon MinGW which supports x64. GCC which is currently the de facto compiler of choice for *nix users, though LLVM is starting to come up strong.
For the (mostly) complete *nix experience, I'd get the MSYS setup available from the main MinGW distribution. Your new favorite phrase will become
[source lang="bash"]./configure --prefix=/mingw && make && make install[/source]
For a complete MinGW setup, I'd check out this site: ([b]Warning: LENGTHY, BUT WORTH IT[/b].)
[url="http://ingar.satgnu.net/devenv/mingw32/index.html"]http://ingar.satgnu....gw32/index.html[/url]

Moving from Java though, as stated above, the biggest issues is memory management. Every object you allocate NEEDS to be deleted. Pointers go hand in hand with this one. Are you sending to a pointer to an object or a pointer to a pointer to an object? This will become important later on in your explorations.
For leaks, I found this, but haven't gotten around to using it (I tend to do things by hand - and consequently rarely get things done.)
[url="http://www.mingw.org/wiki/HOWTO_compile_and_use_the_mpatrol_memory_leak_detection_library"]MPatrol[/url] (Setup for MinGW)

As for libraries, the best things in life are free, or so I've been told.
For standard everything but the kitchen sink library needs, the Boost Libraries will cure what ails you.
SDL is the game library everyone starts with. (You'll also want SDLImage, SDLNet, and SDLMixer.)
SFML is an excellent "next-step" game library.
For pure 3D, you've got Irrlicht and Ogre3D. Edited by Altruist
2

##### Share on other sites
[quote name='alnite' timestamp='1351621010' post='4995503']
[quote name='Moe091' timestamp='1351614913' post='4995474']
Hmmm. that actually sounds like a good idea, my main goal here is to learn everything thoroughly and properly from the beginning so I can be a good c++ programmer soon. I think forcing myself to do that will help me learn things that I'd usually just happily ignore and let my IDE do it for me. How important and how hard is learning all that? Anyone else think this is a good idea?
[/quote]

A command-line compiler is a great tool to learn. You will use it at some point in your career, and I'd recommend using that over an IDE at this point in time. IDE like VS can spout out error because of IDE config errors, not your code. This can confuse beginners a lot, thinking that their code is wrong while in fact, the IDE is messed up.

[/quote]

I disagree. Do you want to learn the language or the toolchain? If you're learning a language, the error is far more likely to be in your code than the IDE config. The same cannot be said of command line compilers. I'm not saying they're not a useful tool, but I don't feel they're helpful for beginners.

[quote name='joew' timestamp='1351563540' post='4995261']
Regarding setting the pointer to null after deletion this is something I absolutely disagree with and is just inviting bugs to linger in your codebase. By setting to null you won't catch any double delete errors, etc which would be found and handled easily by attempted to delete something that has already been deallocated.
[/quote]

I disagree with your disagreement [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]
Deleting an object doesn't necessarily overwrite the memory. It's quite common for code like this to work
[CODE]
struct Thingy
{
int Something;
};

Thingy* thing = new Thingy();
thing->Something = 42;
delete thing;
ASSERT(thing->Something == 42);
[/CODE]
If you set the pointer to null, this will blow up (a Good Thing(tm)). If not, then you have an intermittent runtime problem that's a nightmare to debug. I'd argue that's a more serious error than a double deletion, as deleting a null pointer is officially safe.

Of course, as you said, you should really be using smart pointers and avoid the whole mess anyway![img]http://public.gamedev.net//public/style_emoticons/default/cool.png[/img]
1

##### Share on other sites
[quote name='superman3275' timestamp='1351562252' post='4995256']
Brace yourself for the horrors of memory management
[/quote]

Nowdays, we got good memory leak detectors that point out the actual location in your source code where the memory leak occured.
My favorite is [url="http://vld.codeplex.com/"]Visual Leak Detector[/url](compatible with VS 08, 10 and 12)
I do not think the manual memory management is going to be a "horror".
0

##### Share on other sites
[quote name='lride' timestamp='1351889554' post='4996663']
I do not think the manual memory management is going to be a "horror".
[/quote]
I agree as realistically if using C++11 and RAII properly there shouldn't be much worry about memory management/leaks at all. As mentioned above there are also good tools for tracking things down if needed.. although using std::unique_ptr, std::shared_ptr, and std::weak_ptr effectively really makes things quite simple. I actually find memory management easier in C++11 than using garbage collected languages as the pointer classes are safe and I still control their actual point of destruction... imo it's a win-win. Edited by joew
1

## Create an account

Register a new account