我正在为一个游戏开发课程进行摄入任务,但是在将我的代码分成几个类之后,我被视觉工作室的一个恼人的错误所困扰。错误状态LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
所以我的main函数应该是错误的。我环顾四周,最合乎逻辑的原因似乎是错误的子系统,但这是设置为控制台应用程序。这是我的代码:
Main.cpp的:
#include <Box2D/Box2D.h>
#include <SFML/Graphics.hpp>
#include "Game.hpp"
int main() {
Game game; //Sets up the game
game.populateWorld();
while (game.window.isOpen()) {
game.checkEvents();
game.drawBodies();
game.m_Player->movePlayer();
}
return 0;
}
Game.hpp:
#ifndef Game_hpp
#define Game_hpp
#include <SFML/Graphics.hpp>
#include "World.hpp"
#include "Player.hpp"
class Game {
public:
Game();
void checkEvents();
void drawBodies();//Displays the bodies and keeps the view centered
//Public data members to be used by other classes
sf::Texture backGroundTexture;
sf::Texture playerTex;
sf::Texture platformTex;//Doesn't have a sprite declared since multiple copy's will be made
sf::Sprite backGround;
sf::Sprite player;
sf::View view;
sf::RenderWindow window;
const float m_Scale;//Number of pixels per meter
Player* m_Player = NULL;
World* m_World = NULL;
void populateWorld();
private:
void loadResources();//Loads resources and applies them where needed
};
#endif // !Game_hpp
World.hpp:
#ifndef World_hpp
#define World_hpp
#include <Box2D/Box2D.h>
class World {
public:
//Public member functions
World(const float scale);
~World();
void step();
b2Body* spawnPlayer(float x, float y);
//Public data members
b2World* world = NULL; //Points to the entire world! Handle with care ;)
void createPlatform(b2Vec2 point);
private:
//Private data members
b2Vec2 gravity;
const float m_Scale;
//Declaring step values
float32 m_TimeStep;
int32 m_VelocityIterators;
int32 m_PositionIterators;
};
#endif // !World_hpp
Player.hpp:
#ifndef Player_hpp
#define Player_hpp
#include <Box2D/Box2D.h>
#include "World.hpp"
class Player{
public:
Player(World* world, const float scale, float x, float y);
void movePlayer();
b2Body* m_PlayerBody;//A pointer to the player Character's body needed for the movement
private:
World* m_World;
const float m_Scale;
};
#endif // !Player_hpp
希望任何人都可以指出我正确的方向与错误:)
答案 0 :(得分:0)
猜猜我是无知的...有一个关于main.cpp的警告使用Mac OS X的行结尾,因为我在iMac上工作我不在乎。但是当我在Notepad ++ EDIT -> EOL Conversion -> Windows Format
中修复它时,它就像一个沙姆!我的坏我害怕^^
答案 1 :(得分:-1)
我通过以下方式解决了我的问题:
1)关闭项目并重新启动PC
2)创建一个新项目并关注这个线程因为我在做GUI http://www.bogotobogo.com/cplusplus/application_visual_studio_2013.php