So I'm making a game, and it was working perfectly fine, so I started developing the next part of the game which is the chunking system and the generation (you might be able to tell from my previous posts) but then all of a sudden I got some random linker errors, even though I haven't touched anything in the linker and the game was working perfectly fine before. Here are the errors:
Error 3 error LNK2019: unresolved external symbol "public: class sf::Sprite __thiscall AbstractBlock::draw(void)" (?draw@AbstractBlock@@QAE?AVSprite@sf@@XZ) referenced in function _main C:\(Insert personal stuff here)\Main.obj Top Down Shooter
Error 4 error LNK2019: unresolved external symbol "public: void __thiscall AbstractBlock::destroy(class b2World *)" (?destroy@AbstractBlock@@QAEXPAVb2World@@@Z) referenced in function "public: int __thiscall Universe::saveGame(void)" (?saveGame@Universe@@QAEHXZ) C:\(Insert personal stuff here)\Universe.obj Top Down Shooter
Error 5 error LNK1120: 2 unresolved externals
They don't have line numbers and it appears the problem is in the Universe.obj and main.obj? I honestly don't know what those are, so instead I'm going to post both of the .cpp files in full:
Universe.cpp:
#include "Universe.h"
Universe::Universe(){
world = new b2World(b2Vec2(0, 0));
world->SetAllowSleeping(false);
chunkManager = new ChunkManager(world);
player = new Player(world);
}
Universe::~Universe()
{
}
int Universe::saveGame(){
player->destroy(world);
player = nullptr;
std::list<AbstractBlock>::iterator i;
for (i = getLoadedBlocks()->begin(); i != getLoadedBlocks()->end(); i++){
i->destroy(world);
}
world = nullptr;
return 1;
}
void Universe::spawnEntity(int x, int y, int entityID){
}
std::list<AbstractBlock>* Universe::getLoadedBlocks(){
return chunkManager->getLoadedBlocks();
}
void Universe::update(){
player->update();
world->Step(1 / 60.f, 8, 3);
}
Player* Universe::getPlayer(){
return player;
}
Main.cpp:
#include <iostream>
#include "Box2D\Box2D.h"
#include "SFML/Graphics.hpp"
#include "Universe.h"
#include "simplexnoise.h"
int main(){
static int FPS = 1.f / 60.f;
sf::RenderWindow window(sf::VideoMode(640, 480), "Top Down Shooter");
sf::Event event;
Universe universe;
bool running = true;
int distX;
int distY;
float angle;
while (running){
window.clear(sf::Color::White);
while (window.pollEvent(event)){
switch (event.type){
case sf::Event::Closed:
running = false;
break;
case sf::Event::KeyPressed:
switch (event.key.code){
case sf::Keyboard::Q:
running = false;
break;
case sf::Keyboard::W:
universe.getPlayer()->setMoveUp(true);
break;
case sf::Keyboard::A:
universe.getPlayer()->setMoveLeft(true);
break;
case sf::Keyboard::D:
universe.getPlayer()->setMoveRight(true);
break;
case sf::Keyboard::S:
universe.getPlayer()->setMoveDown(true);
break;
}
break;
case sf::Event::KeyReleased:
switch (event.key.code){
case sf::Keyboard::W:
universe.getPlayer()->setMoveUp(false);
break;
case sf::Keyboard::A:
universe.getPlayer()->setMoveLeft(false);
break;
case sf::Keyboard::D:
universe.getPlayer()->setMoveRight(false);
break;
case sf::Keyboard::S:
universe.getPlayer()->setMoveDown(false);
break;
}
break;
}
}
distX = (sf::Mouse::getPosition().x - universe.getPlayer()->getXpos() - window.getPosition().x - 10);
distY = (sf::Mouse::getPosition().y - universe.getPlayer()->getYpos() - window.getPosition().y - 30);
if (distX != 0){
angle = std::atan2f(distY, distX);
universe.getPlayer()->setAngle(angle + (b2_pi / 2));
}
//Updating the universe
universe.update();
//Drawing Everything
window.draw(universe.getPlayer()->draw());
std::list<AbstractBlock>::iterator i;
for (i = universe.getLoadedBlocks()->begin(); i != universe.getLoadedBlocks()->end(); i++){
window.draw(i->draw());
}
window.display();
}
universe.saveGame();
return 0;
}
So I was trying to figure out the problem on my own, and I thought it may have been the part where I use the iterator and the lists to draw all the current blocks in the universe. I thought this because both the Universe and main .cpp have these small for loops in them (which I just recently added). So I commented out those parts in each file and things got even weirder. Visual Studio 2013 then gave me errors when I ran my program and then would take me to xutility file! I have no idea why! I made sure to comment out the iterator part and tried again but the same thing happened! With those two lines of iterators commented out I'm not using iterators at all in my program! Why would it be taking me to there? Please help i'm so confused >.<
Edit: AbstractBlock.cpp:
#include "AbstractBlock.h"
AbstractBlock::AbstractBlock()
{
}
AbstractBlock::AbstractBlock(int x, int y, float roation, b2World *world){
}
sf::Sprite AbstractBlock::draw(){
sf::Sprite sprite;
return sprite;
}
void AbstractBlock::destroy(b2World *world){
}
AbstractBlock::~AbstractBlock()
{
}
I'm originally a Java programmer, and I wasn't sure if there was a way to make an "abstract" class like you can in Java, so instead I just made a normal class with not to many defined methods, which is then inherited by other classes.
Second Edit: I have also decided to show my Dirt class which extends my AbstracBlock class and so far is the only class that inherits from AbstractBlock:
#include "DirtBlock.h"
DirtBlock::DirtBlock()
{
}
DirtBlock::DirtBlock(int x, int y, float rotation, b2World *world){
bodyDef.position.Set(x, y);
bodyDef.type = b2_dynamicBody;
fixDef.density = .1f;
b2PolygonShape shape;
shape.SetAsBox(16, 16);
fixDef.shape = &shape;
body = world->CreateBody(&bodyDef);
body->CreateFixture(&fixDef);
texture.loadFromFile("dirt.png");
}
void DirtBlock::destroy(b2World *world){
world->DestroyBody(body);
body = nullptr;
}
DirtBlock::~DirtBlock()
{
}
sf::Sprite DirtBlock::draw(){
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setOrigin(16, 16);
sprite.setPosition(body->GetPosition().x, body->GetPosition().y);
return sprite;
}
Third Edit: Also! This is where VisualStudio takes me when I try to run my program:
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Myproxy != _Parent_proxy)
{ // change parentage
_Lockit _Lock(_LOCK_DEBUG);
_Orphan_me();
_Mynextiter = _Parent_proxy->_Myfirstiter;
_Parent_proxy->_Myfirstiter = this;
_Myproxy = _Parent_proxy;
}
It's located in the xutility class and I have no idea what this is.The next line to be performed is the _Mynextiter line.