• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Getting started with C++

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
I've actually never ventured deep enough into C++, but I'm thinking I might as well get started. However, in this uni, C++ is an upperdivision course, and since I'm just finishing my freshman year, I need to go into it self taught. My programming experience is just Java, PHP [lol], and C#. I've done a little bit of assembly, and very minute portions of C++ for homebrew back when I was interested in that.

Sadly, internet tutorials suck, except to learn very basic stuff, so any recommendations on books/compilers, etc would be awesome. Only book I got was C++ for dummies...doesn't help too much, just basic syntax.

Someone suggested this for a book: http://www.amazon.com/exec/obidos/ASIN/0672326973/christopherheng

For compilers/IDEs though I'm uncertain. I have used Dev C++, but I've never liked it. For one the tabbing is/was just horrific, uneven and some tabs are much larger than others, and it just wasn't visually appealing enough for long hours just sitting there. I like Visual Studio, but I'm pretty sure it's attached to .NET, and I can't use it for native C++. If someone knows how to make non .NET code work with it I'm all ears, otherwise, any good C++ IDE recommendations would be awesome. I use Programmer's Notepad for PHP, but I'd like to avoid it for C++.

Since I'd also like to learn cross-platform stuff, a good Linux IDE suggestion would also suffice. I'm planning on installing Fedora Core on my gaming rig [that or the laptop, I feel more comfortable programming on my PC], since I don't care much for Ubuntu. I'd rather find a Windows IDE, since I spend most of my time on it [I game a LOT], but I'll take any suggestions into consideration.

I also need a way to detect Memory Leaks. Is it just look at the Task Manager and check the CPU, Page Fileing, and RAM, or is it something else?

For GUI type applications, I'd rather just use C#, so I'm gonna use C++ for minor programs/games. I already made one game [it's the standard beginner copy something project] in C#, halfway through I was thinking of switching to C++ but I figured I might as well finish it [not done yet, but almost, very close]:
http://www.sendspace.com/file/y7tc8b

I hear SDL is good for cross platform projects, but other than that, abstract everything?

tl;dr - I want to learn C++ and need a good IDE/memory leak check method.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
I looked it up. I'll definitely look into that when I'm working on Linux. Won't work on Windows [which I'd like to know one], but it's a big help.

I'm actually thinking of booting Fedora and OSX [hackintosh] on this comp. 64GB for Fedora, 32GB for OSX, out of 600GB. For testing purposes mostly.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
I only have one monitor [I wish I could get a second but I don't have a desk big enough to fit it], but windowed is fine. It's a gaming rig so I should be able to do it.

However, I assume to use it I need the OSs installed. I know I can use Fedora from within Windows [or the other way around], but I don't know if you can load OSX like that from inside Windows even if you manage to install it.

Specs are 3Ghz Dual Core [non overclocked Intel], 2GB RAM [I might put the second stick in if Fedora is 64bit, I only have 32bit XP], 9600GT. It should work fine.

Planning on quad booting once Windows 7 comes out. Gonna shrink the XP partition to maybe 32GB-64GB and putting the rest for Windows 7. Might as well not throw XP away.
 

TheBuzzSaw

Young Link Extraordinaire
Moderator
BRoomer
Joined
Jul 21, 2005
Messages
10,479
So, install Mac OSX and run Windows/Linux from inside Virtual Box. :p

C++ is my favorite language. It produces programs that run extremely fast, and knowing C++ helps you develop for almost any hardware known to man.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
Of course, I hear you have to delete your HD to install Mac. If that's true, I'm just gonna wait until someone throws away a computer then get parts, like a new HD.

I like C# much more than Java. Hoping I'll like C++. True that on fast.
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
Under linux the most popular IDE is probably eclipse. I love the SDL so much but unfortunately its kind of a hassle under windows, especially considering most people don't even have the SDL library. For my cross-platform c++ stuff I like Qt. Although the same is true about most people not having this library, its really an amazing one and worth the downfall. It reimplements almost everything in c++ in a cross-platform, and in the case of their data structures, radically faster way.

Also I would watch yourself when you start calling languages fast or slow ... Although its true that if you were a systems, networking, and language expert that you might be able to build a thread pool, server, and scripting language from scratch in c++ for your online rpg, chances are that in the month+ that it takes to write all this code that your going to make either some serious bugs, or have serious memory/cpu slowdown in your 10000+ lines of code. In my opinion its much better to write the code in python in three days, and spend the next three days profiling it, and adding c code if needed.

Also from a more practical perspective its always good to have a "scripting" language under your belt. C++, Java, and C# are pretty much the exact same language. The point of these languages is to spend 100 times as much time writing code as executing it. This is why these languages have a reputation of being overly safe. The time it takes to write code for these languages takes so long that the programmer himself becomes a danger to his own code. So your forced to declare private variables, write 1,000,000 getters and setters, and write 3 different functions that do exactly the same thing but take a float, versus, a double, versus an int. The philosophy of interpreted languages is that if you can write in 3 lines what a compiled language can in 30, your less likely to make a mistake.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
I managed to get SDL set up on Visual Studio. All that's really a hassle is the startup, once I abstract away the harder stuff and get a second library working, it'd get much easier. Abstracting away is always the fun part for me. Turning off the preprocessor made things no longer painful.

I never called anything fast or slow though. With C++ it may be faster, but the coding time is slower, like you said. Why I still plan on using C# for some stuff, because it's closer to "writing speed". Mostly, I just want to take a shot at cross compatibility and maybe learn something for the future. Java may be auto cross compatiility, but it requires a seperate large install, and it's just bad for games.

And Online RPG made me lol. Cause I know that's what most people want to do. I'd rather make small simple games once I get an idea. People keep thinking they can make an epic on their own...

I'll try Eclipse.
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
lol well really I meant like a graphical mud, which is really not as epic as it sounds. Good luck with SDL though, and a take a real look about there event handling facilities, they really have a way of making code way more modular and just simpler/beautiful in general if used correctly. You can create custom events that are handled on your game loop the same way things like mousemovement and keyboard input are. Once you have a single game loop that handles all of events the same, your code becomes immune to special cases and everything seems to go much smoother.

Also c# is cross platform, take a look at mono. Its also important to note that XNA is not cross platform ... yet. I'm not sure what you mean when you say that java requires a seperate install because almost everyone has the JRE. Also the notion that java isn't good for video games is really a falsehood. Chances are you've never played a video game written in java thats not browser based. I've written several and they are very very fast, even using Swing, including my own not so epic online rpg :). However if you want to make a radically fast game using openGL there are facilities to do that in Java as well.
 

imirish

Smash Rookie
Joined
Apr 14, 2009
Messages
5
Location
Philadelphia, PA
C# is sort of cross platform. Mono isn't up to the .Net 3.5 standard yet (it's almost there), so you have to be particularly careful when writing for Mono. The way I learned C++ (all of my programming, really) was to look at sources and try to figure out how things were done.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
I have not seen Mono, but I was just using Direct3D and DirectDraw in C#. I'd recompile it in Linux or...something?

I have used Java. It's...weird, to say the least. It's possible but very very awkward. Especially for games, it's possible and of a decent speed, but it just feels weird.

Not EVERY computer has the JRE, but many do. I just don't like the idea of "if you don't have it, download it", which puts me away from XNA as well. With SDL, it's a DLL, at least for Windows.

That Event thing sounds awesome, I'll look at it.
 

noradseven

Smash Lord
Joined
Feb 13, 2009
Messages
1,558
Location
North Carolina
Learn C
C++ isn't used as much as C# or Java and them all being OO languages there is not much of a point in spending reasonable amounts of time learning it.
Assembly is fun too.

lol well really I meant like a graphical mud, which is really not as epic as it sounds. Good luck with SDL though, and a take a real look about there event handling facilities, they really have a way of making code way more modular and just simpler/beautiful in general if used correctly. You can create custom events that are handled on your game loop the same way things like mousemovement and keyboard input are. Once you have a single game loop that handles all of events the same, your code becomes immune to special cases and everything seems to go much smoother.

Also c# is cross platform, take a look at mono. Its also important to note that XNA is not cross platform ... yet. I'm not sure what you mean when you say that java requires a seperate install because almost everyone has the JRE. Also the notion that java isn't good for video games is really a falsehood. Chances are you've never played a video game written in java thats not browser based. I've written several and they are very very fast, even using Swing, including my own not so epic online rpg :). However if you want to make a radically fast game using openGL there are facilities to do that in Java as well.
No java really isn't that great for video games, I have played many games in it and java is a resource hog *gasp*, if you have the computer for it, of course it will run fine. Unless you use openGL in java in which case its not as bad but still its a bit of a hog, and I have had a few problems with reverse compatibly.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
Isn't C++ really just an expanded C? MOST stuff transferring over? And I hear otherwise on C++'s use...maybe they mean a combination of both.

Mostly, I want to make a program cross compatible. C# is cross compatibile in theory, but, bit of a hassle, correct me on that?
 

ColinJF

Smash Ace
Joined
Dec 21, 2007
Messages
712
C++ is almost a superset of C, but not quite. Idiomatic C++ looks much different from idiomatic C, however; good C++ does not look anything like good C. User noradseven is wrong by the way; C++ is extremely popular, and idiotic C++ is quite a bit different from idiomatic Java, so it will be worth learning.

It's very possible to write cross platform C++ if you know what you are doing. Some things, like sockets, threads, etc. have no cross platform interface in the standard library, so you'll probably want to make use of an external library like Boost if you are going to write cross platform C++ that uses these platform facilities.

Also you mention memory leaks a lot. Memory leaks are not something you will have to contend with if you write idiomatic C++. In particular, use STL container overs arrays, and use smart pointer classes to hold the result of operator new. Only use operator new if you actually want the memory to outlive the present scope. In well written C++ most if not all resources will free themselves via the RAII idiom.

Explicitly freeing memory (e.g. via operator delete) in high level code is often indicative of poor code because if something between the point of allocation and deletion throws an exception it will be impossible to reclaim the memory without very carefully written try...catch code; in well written code objects tend to be on the stack and their deconstructor reclaims any resources they are using. Objects' deconstructors will run even in case of an exception.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
What about for stuff that have to outlive the current scope? Global variables? And, what if you have to clear a room, or "a monster dies", for example?

Seems more than learning the language needs to be learned. Eh well.

and idiotic C++ is quite a bit different from idiomatic Java
I lold. Cause it's true.
 

ColinJF

Smash Ace
Joined
Dec 21, 2007
Messages
712
What about for stuff that have to outlive the current scope?
Generally you should use a container class to hold the result of operator new, like std::auto_ptr (move semantics) or boost::shared_ptr (copy semantics).

[Edit: Wow, hours later I realised that typo when I was thinking about it... I meant "idiomatic" not idiotic, heh.]
 
Top Bottom