Problem przy dzieleniu plików, multiple definition of 'MAP'
Ostatnio zmodyfikowano 2012-06-10 19:54
tomcionek15 Temat założony przez niniejszego użytkownika |
Problem przy dzieleniu plików, multiple definition of 'MAP' » 2012-06-10 17:25:07 Siemka to znowu ja, podczas dzielenia plików mam problem, najpierw podam kody :
#include <iostream> #include "game.h"
using namespace std;
void Game::setPositionX( int posX ) { player.x = posX; }
int Game::getPositionX() { return player.x; }
void Game::clearMap() { system( "cls" ); }
void Game::addEntity( EntityType block, int posX, int posY ) { if( block == PLAYER ) { MAP[ posX ][ posY ] = 1; } if( block == ENEMY ) { MAP[ posX ][ posY ] = 2; } if( block == WALL ) { MAP[ posX ][ posY ] = 3; } if( block == EMPTY ) { MAP[ posX ][ posY ] = 4; } }
void Game::drawMap() { for( int y = 0; y < 20; y++ ) { for( int x = 0; x < 30; x++ ) { switch( MAP[ x ][ y ] ) { case 1: cout << "#"; case 2: cout << "@"; case 3: cout << "|"; case 4: cout << " "; } } } }
#ifndef GAME_H_INCLUDED #define GAME_H_INCLUDED
#include <cstdlib>
int MAP[ 30 ][ 20 ];
struct Position2D { int x; };
enum EntityType { PLAYER = 1, ENEMY, WALL, EMPTY }; Position2D player;
class Game { private: int score; public: Game() : score( 0 ) { player.x =( sizeof MAP / 2 ); } void setPositionX( int posX ); int getPositionX(); void clearMap(); void addEntity( EntityType block, int posX, int posY ); void drawMap(); };
#endif
#include <iostream> #include "game.h"
using namespace std;
int main() { Game gra; gra.addEntity( PLAYER, 5, 10 ); for(;; ) { gra.clearMap(); gra.drawMap(); } return 0; }
a tu błędy : \game.cpp|6|multiple definition of `MAP'| \main.cpp|7|first defined here| ||=== Build finished: 2 errors, 0 warnings ===|
totalnie nie kapuje co jest źle, dwa razy zdefiniowana 'MAP', jak mam tylko raz ? |
|
m4tx |
» 2012-06-10 17:34:32 2 razy załączasz game.h , czyli 2 razy definiujesz zmienną globalną MAP. |
|
tomcionek15 Temat założony przez niniejszego użytkownika |
» 2012-06-10 19:54:34 dobra działa, dzięki :] |
|
« 1 » |