Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sirSolarius

Static inherited data problem

This topic is 5276 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an std::list in my base MemObj class, and that class is inherited by myriad others. When I try to compile it with the static std::list, I get lots of errors. MemObj class:
#include <assert.h>
#include <list>

/////////////////////////////////////////////////////////////////////////////

//	MEMOBJ.H

/////////////////////////////////////////////////////////////////////////////

//

// AUTHOR: ERIK GOLDMAN

// DATE:  6-3-04

// DESC: The base memory-managed object class

// NOTES:

// TOFIX:

/////////////////////////////////////////////////////////////////////////////

class MemObj
{
protected:
	int m_refs;

public:
	static std::list<MemObj*> m_deadObjects;

	MemObj()
	:m_refs(0)
	{
	}

	virtual ~MemObj()
	{
	}

	void attach()
	{
		++m_refs;
	}
	void release()
	{
		--m_refs;
		if(m_refs==0)		// nothing points to the object

		{
			//MemoryManager::getInstance()->markForDeletion(this);

			m_deadObjects.push_back(this);		// mark for deletion

		}
	}
};
std::list<MemObj*> MemObj::m_deadObjects;
And I get this error:
Linking...
MemoryManager.obj : error LNK2005: "public: static class std::list<class MemObj *,class std::allocator<class MemObj *> > MemObj::m_deadObjects" (?m_deadObjects@MemObj@@2V?$list@PAVMemObj@@V?$allocator@PAVMemObj@@@std@@@std@@A) already defined in Inp
utKeymap.obj
KutatasMain.obj : error LNK2005: "public: static class std::list<class MemObj *,class std::allocator<class MemObj *> > MemObj::m_deadObjects" (?m_deadObjects@MemObj@@2V?$list@PAVMemObj@@V?$allocator@PAVMemObj@@@std@@@std@@A) already defined in Input
Keymap.obj
Debug/KutatasEngine.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Here is the InputKeymap, if you''re interested:
/////////////////////////////////////////////////////////////////////////////

//	INPUTKEYMAP.H

/////////////////////////////////////////////////////////////////////////////

//

// AUTHOR: ERIK GOLDMAN

// DATE:  6-3-04

// DESC: A keymap that queries the InputManager for keys assigned to Functors

// NOTES:

// TOFIX:

/////////////////////////////////////////////////////////////////////////////


#if !defined(AFX_INPUTKEYMAP_H__C318C97E_9332_428F_B553_58DD3CBBE822__INCLUDED_)
#define AFX_INPUTKEYMAP_H__C318C97E_9332_428F_B553_58DD3CBBE822__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include <map>
#include "Functor.h"
#include "InputManager.h"

class InputKeymap:public MemObj  
{
public:
	InputKeymap();
	~InputKeymap();

	void Assign(int key, MemPtr<Functor> &f);
	void Unassign(int key);

	void Erase();

	void Update();

protected:
	std::map<int, MemPtr<Functor> > m_keymap;
};

#endif // !defined(AFX_INPUTKEYMAP_H__C318C97E_9332_428F_B553_58DD3CBBE822__INCLUDED_)


What is going on, and how can I fix it?

Share this post


Link to post
Share on other sites
Advertisement
You''re declaring storage for a static in a header which is non-kosher. Move the
std::list<MemObj*> MemObj::m_deadObjects;
from the header file to exactly one of your source files.

Share this post


Link to post
Share on other sites
It would also be advisiable to put some include guards around your header file while you're at it. It looks like you keymap header has them, but the MemObj header does not.

[edited by - leiavoia on June 10, 2004 4:58:53 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!