Thread: Namespace Problem, *sigh*

  1. #1
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195

    Namespace Problem, *sigh*

    Hi, Im using namespaces for one of my assignments and its really boggling my mind. Here is my class:

    Code:
    #ifdef _GAMETREE_
    #define _GAMETREE_
    
    // My Namespace
    namespace Mastadex
    {
    	// Macros to make my Life Easier
    	#define BOARDSIZE 30
    
    	typedef struct Node
    	{
    		Node *Parent;					// Pointer to the Parent Board
    
    		int BoardValue;					// The Value of the board
    		int BestMove, WorstMove;		// Represents a Numerical Value equal to an Index in the Array of Possible Moves
    		int Board[6][5];				// The Board Itself
    
    		Node *NextMove[BOARDSIZE];		// An Array of Pointers to Board Configs
    	};
    
    	class GameTree
    	{
    		Node *RootNode;					// Root Node
    		Node *CurrentNode;				// Current Node that is being Pointed To
    		int MoveX;						// Recommended Move X
    		int MoveY;						// Recommended Move Y
    
    		//int EvaluateBoard(int Board[][6]);
    		//void ClearTree();
    		//void CopyBoard(int ToBoard[][6], int FromBoard[][6]);
    
    	public:
    
    		GameTree()
    		{
    // NOTHING YET
    		}
    		~GameTree()
    		{
    // NOTHING YET
    		}
    		//void MapBoard(int Board[][6]);
    		//void RecommendedMove(int &X, int &Y);
    	};
    
    	void GetLocation(int &X, int &Y, int Board[][6])
    	{
    // NOTHING YET
    	}
    }
    
    #endif
    Here is My Main:

    Code:
    #include "header.h"
    
    int main(int argc, char *argv[])
    {
    	int board[5][6];
    	int loc1, loc2;
    
    	Mastadex::GetLocation(loc1, loc2, board);
    
    	return 0;
    }

    In the main, im getting this error at the GetLocation functioncall in VS.NET: error C2653: 'Mastadex' : is not a class or namespace name

    Ignore the fact that this class does nothing, im just trying to get it compiling right now. This is my first time dealing with namespaces, I have no idea how to fix this. Help?

    EDIT: Im using Visual Studio .NET 7.1
    Last edited by Mastadex; 04-11-2005 at 11:19 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Code:
    #include "header.h"
    Code:
    #ifdef _GAMETREE_
    #define _GAMETREE_
    You sure your header file with the class is called header.h?

    Did you ever consider closing that program, and creating another simple program to test out namespaces? You might even want to create a program called something like Tester. Then, whenever you need to test something out, you won't have to go to the trouble of creating a new project--you can just open Tester and write some code you want to test out.

    Here is a simple example of a namespace:
    Code:
    #include <iostream>
    using namespace std;
    
    namespace Mastadex
    {
    
    	void GetLocation()
    	{
    		cout<<"hello"<<endl;
    	}
    
    }
    
    int main()
    {
    	Mastadex::GetLocation();
    
    	return 0;
    }
    Or, divided into multiple files it would look like this:

    test.h
    --------
    Code:
    #include <iostream>
    using namespace std;
    
    namespace Mastadex
    {
    
    	void GetLocation()
    	{
    		cout<<"hello"<<endl;
    	}
    
    }
    main.cpp
    -----------
    Code:
    #include <iostream>
    #include "test.h"
    using namespace std;
    
    int main()
    {
    	Mastadex::GetLocation();
    
    	return 0;
    }
    Last edited by 7stud; 04-11-2005 at 11:30 PM.

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Umm maybe try using ifndef instead
    Woop?

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    #ifdef _GAMETREE_
    #define _GAMETREE_
    I assume this is an inclusion guard. You should use ifndef instead, only include it if it has NOT been defined yet.

    #define BOARDSIZE 30
    For constants use the const keyword instead, it' much safer and has type checks:
    Code:
    const int BOARDSIZE = 30;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    Yea, my guess is your whole problem being you said #ifdef, and not #ifndef.
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern namespace?
    By Brafil in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2009, 08:06 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Problem with atoi()?
    By ruthgrin in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2006, 12:25 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM