Well, the basic structure is a form which uses multiple classes defined in seperate files.
Below is my controller class which is supposed to keep track of which files are opened. It's included in both the form and the Map.cpp file, which contains all Map function implementations. I'm supposing these files aren't needed here because all they do is include the file seen below.

Controller.h

#ifndef	CONTROLLER_H_INCLUDED
#define CONTROLLER_H_INCLUDED

#include "Map.h"
#include "Array.h"

class Controller
{
	public:
		Controller() {}
		~Controller() {}

		//Retreive private data
		static Map GetCurrentMap() {return *currentMap;}

		//Set private data
		static void SetCurrentMap(Map map) {currentMap = ↦}

		//Opened maps
		static Arrayy<Map> Maps;

	private:
		//Current active map in editor window
		static Map* currentMap;
};

	Map* Controller::currentMap;  //Saving space for static variable
	Arrayy<Map> Controller::Maps;  //Saving space for static variable


#endif //CONTROLLER_H_INCLUDED

Compiler errors:

1>Mapeditor.obj : error LNK2005: "private: static class Map * Controller::currentMap" (?currentMap@Controller@@$$Q0PAVMap@@A) already defined in Map.obj
1>Mapeditor.obj : error LNK2005: "public: static class Arrayy<class Map> Controller::Maps" (?Maps@Controller@@$$Q2V?$Arrayy@VMap@@@@A) already defined in Map.obj

It seems the "Controller.h" file is included twice, which it should be.. But normally it should skip to #endif and not overwrite the static variable declarations. Yet I have no idea why it doesn't.
If it matters for anything, I'm using visual c++ 2008. I've been messing around with the options, but that seemed to result in nothing but more errors..

Thanks for any input :)

Recommended Answers

All 2 Replies

Lines 27 and 28 can only appear in ONE *.cpp file -- doesn't matter which one. Remove those lines from the header file.

Solved it, thanks... Should've thought of that of my own :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.