using namespace

This is a discussion on using namespace within the C++ Programming forums, part of the General Programming Boards category; hi just wondering about this i'm using dev-c++ 4.9.9.2 Code: /* Simple tictactoe program Human vs Human */ using namespace ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Location
    Jilin Province, China
    Posts
    7

    using namespace

    hi

    just wondering about this i'm using dev-c++ 4.9.9.2

    Code:
      /* Simple tictactoe program Human vs Human */
    using namespace std;
    #include<iostream>
    #include<string>
    	
    namespace board {
    	char board[3][3];	// contains the board array	
    	int i=0;	// I put this here because it was getting resest to 0 after cin 
    }
    
    /*
    
    Draw tic tac toe board
    
    */
    void board_draw()
    {
    	using namespace board;
    	cout << "\n";
    	cout << "  A B C \n\n";  
    
    	for (int x=0;x<3;x++) {    
     		cout << x << " ";
        for (int y=0;y<3;y++) {
        	cout << board[x][y];
    i get the error:

    D:\Dev-Cpp\source\TicTacToe\main.cpp In function `void board_draw()':
    25 D:\Dev-Cpp\source\TicTacToe\main.cpp `board' undeclared (first use this function)

    if i use

    Code:
    board::board[x][y] 
    it compiles ok

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    changing the name of board[x][y] should fix your problem

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Having a namespace with the same name as a variable is asking for trouble.

  4. #4
    Registered User
    Join Date
    Jul 2005
    Location
    Jilin Province, China
    Posts
    7
    yeah thanks it does

    that was quite foolish of me....



    malc

  5. #5
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    The function should reside within the namespace, not outside.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

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, 04:11 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. data validation & namespace
    By tiange in forum C++ Programming
    Replies: 4
    Last Post: 07-05-2005, 03:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21