Skip to main content
gamedev.net
🔒 Locked

link error

Started by Freaker13 4 replies 250+ views
Original Post
Freaker13
Freaker13
hi all, i''ve got a static library with a class with a static member. In my application i get those link errors: estGame.obj : error LNK2001: unresolved external symbol "private: static class iInput * cInputTask::input" (?input@cInputTask@@0PAViInput@@A) Engine.lib(cInputTask.obj) : error LNK2001: unresolved external symbol "private: static class iInput * cInputTask::input" (?input@cInputTask@@0PAViInput@@A) the class in my static lib .h:
#ifndef CINPUTTASK
#define CINPUTTASK
#include <windows.h>
#include "InputInc.h"
#include "assert.h"
#include "cInputTask.h"
#include "iTask.h"

class cInputTask : public iTask
{
public:
	cInputTask();
	~cInputTask();
	void init(char *dllName,HINSTANCE hInst,HWND hWnd);
	bool start();
	bool update();
	void stop();
	static inline iInput* getInputObj(){return input;}	
private:
	cInputFactory	*factory;
	static iInput	*input;
	HINSTANCE		hInst;
	HWND			hWnd;
	char			*dllName;
};
#endif
.cpp:
#include "stdafx.h"
#include "cInputTask.h"
iInput	cInputTask::*input = NULL;

cInputTask::cInputTask()
{
	factory = NULL;
	this->hInst = NULL;
	this->hWnd = NULL;
	dllName = NULL;
}
	
cInputTask::~cInputTask()
{
	
}

void cInputTask::init(char *dllName,HINSTANCE hInst,HWND hWnd)
{
	this->hInst = hInst;
	this->hWnd = hWnd;
	this->dllName = dllName;
}

bool cInputTask::start()
{
	assert(hInst!=NULL||hWnd!=NULL||dllName!=NULL);
	
	//create input

	factory = new cInputFactory(hInst);
	factory->initInterface(dllName);
	input = factory->getInput(); 
	if(input == NULL)
		return false;

	if(input->init() == false)
		return false;
	
	input->setHWND(hWnd);
	//input->update();

	return true;
}

bool cInputTask::update()
{
	input->update();
	return true;
}

void cInputTask::stop()
{
	factory->destroyInterface();
}
the class in my application:
#ifndef GAMESTATE1
#define GAMESTATE1
#include "Engine Includes.h"

class gameState1 : public iTask
{
public:
	bool start()
	{
		return true;
	}
	bool update() 
	{
		if(cInputTask::getInputObj()->keyPressed(DIK_ESCAPE))
			cKernel::getSingleton().endRun = true;
		return true;
	}

	void stop() 
	{

	}

	
private:
	
};
#endif
xorjesus
xorjesus
I didn''t even realize you could use the static keyword on member functions. I thought static meant the memory address would be considered global and only created once. Wouldn''t this create problems if you call the function more than once with different values for variables ??? Maybe I''m completely off track and someone wants to help us both.
I study day and night, memorizing the game.
Zahlman
Zahlman
"static" member functions are basically just free functions which use the current class as a namespace. They are "shared" between object instances in the same way that static data members are; and ''this'' is not usable within them. Existing in only one location and not being re-creatable, btw, is not a problem for a function; it''s a piece of *code* after all. A place for the program counter to jump to.

To the OP: you''re probably going to need something like "extern iInput cInputTask::*input;" in .h files for the .cpp''s which use them.
Freaker13
Freaker13
thx for fast reply,
i already tried including extern iInput cInputTask::*input but that doesn''t help.

fredizzimo
fredizzimo
iInput cInputTask::*input = NULL;
should be
iInput* cInputTask::input = NULL;
Freaker13
Freaker13
of course
thx

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.