Okay, thirty minutes of fruitless trial and error.
Can someone help? D:
I get these errors:
1>main.obj : error LNK2005: "public: virtual int __thiscall GenericObject::draw(class TCODConsole *)" (?draw@GenericObject@@UAEHPAVTCODConsole@@@Z) already defined in Engine.obj
1>main.obj : error LNK2005: "public: virtual int __thiscall Cursor::draw(class TCODConsole *)" (?draw@Cursor@@UAEHPAVTCODConsole@@@Z) already defined in Engine.obj
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Engine.obj : error LNK2001: unresolved external symbol "struct PODS POD" (?POD@@3UPODS@@A)
Relevant files:
#include "Engine.h"
//#include "Baseclass.h"
#include "PODS.h"
using namespace std;
//Cursor cursors(20,20);
extern PODS POD;
Engine CursesEngine;
bool Engine::EngineInit()
{
return true;
}
void Engine::Update()
{
}
void Engine::Render(TCODConsole *root)
{
POD.cursors.draw(root);
/*root->setChar(30,20,64);
root->setCharForeground(30,20,TCODColor::yellow);
root->setCharBackground(30,20,TCODColor::black);*/
}
void Engine::EngineEnd()
{
}
//
void Engine::Resize(int new_w,int new_h)
{
}
void Engine::WindowActive()
{
}
void Engine::WindowInactive()
{
}
void Engine::KeyUp(const int &key,const int &unicode)
{
if (key == SDLK_UP)
POD.keybuffer1 = 0;
if (key == SDLK_DOWN)
POD.keybuffer1 = 0;
if (key == SDLK_LEFT)
POD.keybuffer1 = 0;
if (key == SDLK_RIGHT)
POD.keybuffer1 = 0;
}
void Engine::KeyDown(const int &key,const int &unicode)
{
if (key == SDLK_UP)
POD.keybuffer1 = KEYS::kUP;
if (key == SDLK_DOWN)
POD.keybuffer1 = KEYS::kDOWN;
if (key == SDLK_LEFT)
POD.keybuffer1 = KEYS::kLEFT;
if (key == SDLK_RIGHT)
POD.keybuffer1 = KEYS::kRIGHT;
}
void Engine::MouseMoved(const int &iButton,const int &iX,const int &iY,const int &iRelX,const int &iRelY)
{
}
void Engine::MouseButtonUp(const int &iButton,const int &iX,const int &iY,const int &iRelX,const int &iRelY)
{
}
void Engine::MouseButtonDown(const int &iButton,const int &iX,const int &iY,const int &iRelX,const int &iRelY)
{
}
#ifndef PODS_H
#define PODS_H
#include "Baseclass.h"
struct PODS //this is a plain old data structure. Nothing to see here, move on.
{
Cursor cursors;
int keybuffer1;
};
#endif
#ifndef BASECLASS_H
#define BASECLASS_H
#include "TCODEngine.h"
using namespace std;
enum ERRORCODE {TEST = -1, NONE = 0};
enum ASCII {AT = 64};
enum KEYS {kUP, kDOWN, kLEFT, kRIGHT};
class GenericObject
{
public:
virtual int draw(TCODConsole *root);
protected:
int character; //the object's character
TCODColor forecolor; //foreground color
TCODColor backcolor; //background color
};
class Cursor : public GenericObject
{
public:
Cursor(int xcoord= 30, int ycoord = 20)
{x = xcoord; y = ycoord; character = ASCII::AT; forecolor = TCODColor::yellow; backcolor = TCODColor::black;}; //initialize cursor to 30 and 20 if no other number is provided.
virtual int draw(TCODConsole *root);
private:
int x;
int y;
};
int GenericObject::draw(TCODConsole *root)
{
return ERRORCODE::NONE;
}
int Cursor::draw(TCODConsole *root)
{
root->putChar(x, y, ASCII::AT);
root->setCharForeground(x, y, forecolor);
root->setCharBackground(x, y, backcolor);
return ERRORCODE::NONE;
/*
root->putChar(30, 20, ASCII::AT);
root->setCharForeground(30, 20, TCODColor::yellow);
root->setCharBackground(x, y, TCODColor::black);
return ERRORCODE::TEST;*/
}
#endif
#include "Engine.h"
#include "PODS.h"
extern PODS POD;
int main(int argc,char *argv[])
{
PODS POD;
CursesEngine.Init("This is a window.","asciisquare.bmp",60,40);
CursesEngine.Start();
CursesEngine.End();
return 0;
}
From what I can see, the draw functions are somehow defined twice. I don't see how.
I also can't see why PODS POD is unresolved, when it's in both main and everywhere as extern. I'm kinda frustrated, since there was a "left of . must be a function" sort of error that I didn't know what was the cause, nor the cure. It disappeared sometime.