我想封裝一個基於sprite的遊戲,並且遇到訪問具有相同命名空間的類時遇到問題。 下面是命名空間代碼:命名空間和類嵌套問題
namespace Client
{
public class Bomb : public Entity
{
private:
int tiempo;
TipoBomba tipo;
public:
Bomb(int px, int py, int tiempo, TipoBomba tipo);
int getX();
int getY();
int getTiempo();
void setTiempo(int t);
Client::TipoBomba getTipo();
void reducirTiempo();
void Mostrar(Graphics^gr);
void explotar(Graphics^gr);
};
public class Game
{
int nivel;
LivingEntity* objJugador;
//Enemigo* objEnemigo;
public:
~Game(void);
Game(void);
static int ** matriz;
static std::vector<Bomb*> bombas;
static bool isBloque(int px, int py);
static bool isVacio(int px, int py);
static void romperBloque(int px, int py, Graphics^ gr);
static bool isRompible(int px, int py);
static bool isBomba(int px, int py);
Point getPrimeraPosicionJugador();
static void addBomba(Bomb* b);
static void cargarMatriz();
void setDireccion_Jugador(Direccion dir);
void Crear_Enemigo(int px, int py);
void Crear_Jugador(int px, int py);
void Mover_Entidades(Graphics^ gr);
Client::Player* getJugador();
int getNivel();
void setNivel(int n);
};
public class Player : public LivingEntity
{
int vidas;
int bombas;
public:
Player(void);
Player(int px, int py);
void Mostrar(Graphics^ gr);
void Mover(Graphics^ gr);
int getVidas();
int getBombas();
void setBombas(int bombas);
void setVidas(int vidas);
};
public class Enemy : public LivingEntity
{
public:
~Enemy(void);
Enemy(void);
Enemy(int px, int py);
void Mover(Graphics^ gr);
void Mostrar(Graphics^ gr);
};
public enum TipoBomba
{
BASICA,
GRANDE
};
}
的警告是:
Warning 60 warning C4183: 'getJugador': missing return type; assumed to be a member function returning 'int'
Warning 37 warning C4183: 'getTipo': missing return type; assumed to be a member function returning 'int'
,並且錯誤是:
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 10 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我試圖從客戶端改變::播放器只播放器(帶TipoBomba相同),並沒有奏效。我也嘗試在課前公開課,而且還是一樣的。是否有任何關鍵字的我需要使用或只是命名空間語義.Thanks
編輯:
一切工作,現在誰在編譯時,我得到了很多的鏈接錯誤的。示例:
Error 10 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 26 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 42 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 58 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 2 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 18 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 34 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 50 error LNK2005: "public: __thiscall Entity::Entity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 13 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 29 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 45 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 61 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 5 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 21 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 37 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 53 error LNK2005: "public: __thiscall LivingEntity::LivingEntity(int,int,char *,int,int)" ([email protected]@[email protected]@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 14 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 30 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 46 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 62 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 6 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 22 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 38 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 54 error LNK2005: "public: enum Direccion __thiscall LivingEntity::getMovimiento(void)" ([email protected]@@[email protected]@XZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 11 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 27 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 43 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 59 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 3 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 19 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 35 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 51 error LNK2005: "public: int __thiscall Entity::getX(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 12 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 28 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 44 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 60 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@$$FQAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 4 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 20 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 36 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 52 error LNK2005: "public: int __thiscall Entity::getY(void)" ([email protected]@@QAEHXZ) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 15 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 31 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 47 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 63 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 7 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 23 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 39 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 55 error LNK2005: "public: void __thiscall LivingEntity::setDx(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 16 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 32 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 48 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 64 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 8 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 24 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 40 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 56 error LNK2005: "public: void __thiscall LivingEntity::setDy(int)" ([email protected]@@[email protected]) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 17 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 33 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 49 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 65 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 9 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Enemy.obj BombermanUPC
Error 25 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 41 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 57 error LNK2005: "public: void __thiscall LivingEntity::setMovimiento(enum Direccion)" ([email protected]@@[email protected]@@Z) already defined in Bomb.obj C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Player.obj BombermanUPC
Error 69 error LNK2019: unresolved external symbol "public: int __thiscall Client::Bomb::getX(void)" ([email protected]@[email protected]@$$FQAEHXZ) referenced in function "public: static bool __cdecl Client::Game::isBomba(int,int)" ([email protected]@[email protected]@[email protected]) C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 70 error LNK2019: unresolved external symbol "public: int __thiscall Client::Bomb::getY(void)" ([email protected]@[email protected]@$$FQAEHXZ) referenced in function "public: static bool __cdecl Client::Game::isBomba(int,int)" ([email protected]@[email protected]@[email protected]) C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 71 error LNK2019: unresolved external symbol "public: static void __cdecl Client::Game::addBomba(class Client::Bomb *)" ([email protected]@[email protected]@[email protected]@@Z) referenced in function "private: void __clrcall BombermanUPC::MyForm::Key_Press(class System::Object ^,class System::Windows::Forms::KeyEventArgs ^)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@@Z) C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 68 error LNK2028: unresolved token (0A000107) "public: static void __cdecl Client::Game::addBomba(class Client::Bomb *)" ([email protected]@[email protected]@[email protected]@@Z) referenced in function "private: void __clrcall BombermanUPC::MyForm::Key_Press(class System::Object ^,class System::Windows::Forms::KeyEventArgs ^)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@@Z) C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\MyForm.obj BombermanUPC
Error 66 error LNK2028: unresolved token (0A00047F) "public: int __thiscall Client::Bomb::getX(void)" ([email protected]@[email protected]@$$FQAEHXZ) referenced in function "public: static bool __cdecl Client::Game::isBomba(int,int)" ([email protected]@[email protected]@[email protected]) C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
Error 67 error LNK2028: unresolved token (0A000480) "public: int __thiscall Client::Bomb::getY(void)" ([email protected]@[email protected]@$$FQAEHXZ) referenced in function "public: static bool __cdecl Client::Game::isBomba(int,int)" ([email protected]@[email protected]@[email protected]) C:\Users\Martin\documents\visual studio 2013\Projects\BombermanUPC\BombermanUPC\Game.obj BombermanUPC
我正在使用該結構來避免循環包含。還使用非託管類來確保我是控制memore和刪除實例的人。 – MartinStone
我的確如所告知的那樣,無論誰現在我在收集時都會遇到很多Linker錯誤。 – MartinStone
您需要將方法聲明放在頭文件中,並在.cpp文件中實現方法。 –