MS Visual C++ vs. Mac Xcode

As a few of you already know, I have started teaching myself c++ with a book called "Beginning C++ Through Game Programming." I've been using MS Visual C++ Express Edition, but my PC is really old and really slow, and it would be much easier to code on my Mac. So I installed Xcode, but when I tried entering a program from the book, it generated an error, and this exact same program worked fine on Visual C++. The error message was for this line

difficulty myDifficulty = EASY;

and the error message was

Unused variable 'myDifficulty'

It seems to me that 'myDifficulty' should have been declared, but since it worked on my PC, I'm assuming there's probably a concept here that I'm not understanding, since my understanding of c++ is extremely limited.

Anyway, I'm just wondering if I should go back to entering these programs on my old PC, or if there's a way to make them work on my new(ish) Mac. I can't afford a new computer right now, so those are my only options.

#include <iostream>
using namespace std;

int main()
	const int ALIEN_POINTS = 150;
	int aliensKilled = 10;
	int score = aliensKilled * ALIEN_POINTS;
	cout << "score: " << score << endl;

	difficulty myDifficulty = EASY;

	enum shipCost {FIGHTER_COST = 25, BOMBER_COST, CRUISER_COST = 50};
	shipCost myShipCost = BOMBER_COST;
	cout << "\nTo upgrade my ship to a Cruiser will cost " 
         << (CRUISER_COST - myShipCost) << " Resource Points.\n";

	return 0;
It's not an error, its a warning. Try removing the Warnings flag
the error message was

Unused variable 'myDifficulty'

That is not an error. It is a warning. You do declare and initialize a variable, but you don't use it later anywhere (yet). The compiler makes a remark about that, since reserving memory for values, but not using it seems like a waste of both CPU cycles and RAM.

If it really is flagged as error, then the compiler has been told to treat warnings as errors. You can tweak the compiler options.
Thanks for your help guys. I guess I was assuming that those warnings were the reason that my code wouldn't run, but now that I look closer, I think there's another issue going on. When I click "Build and Run" it says "Failed" at the bottom of the screen, and when I click that, I get this message:

Duplicate symbol _main in /Users/jeremybell/Documents/CPP docs/Game_Stats3b/build/ and /Users/jeremybell/Documents/CPP docs/Game_Stats3b/build/

Command /Developer/usr/bin/g++-4.2 failed with exit code 1

I think the issue is probably that I don't really know how to use Xcode. The book that I'm using only explains how to use MS Visual C++ Express. I tried looking through the documentation for Xcode, but it assumes a level of proficiency that I don't yet have. Ah well... perhaps I'd better stick to using the old PC, unless maybe there's someone here who knows Xcode?
Best: Use TextWrangler and Make
Okay, I just did a Google search for my error message, and I figured it out. Xcode automatically creates a main.cpp file in the source folder, and then I created another .cpp file, so I had two main() functions. I just had to delete one. Anyway, thanks again for your help.

Hey Agt, I know what TextWrangler is, but what is Make? I looked for it in VersionTracker, but no luck.
^ This will help you get started with make. I think there is an OSX Version of make(Hopefully?).
Other than TextWrangler, you can use gEdit or gVim or TextEdit or whatever goads your goat.
Last edited on
Topic archived. No new replies allowed.