Archived

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

Normie

Linker problem with static member variables

Recommended Posts

Normie    122
Ok, I have a class that looks something like this (this is Window.h):
#ifndef _WINDOW_H
#define _WINDOW_H

class CWindow  
{
public:
	static void SetFullScreen(bool isFullScreen);
	static bool IsFullScreen();
//... commented for space
	static const LPSTR APP_NAME;

private:
	static bool s_IsFullScreen;
//... ditto
};

bool CWindow::s_IsFullScreen = false;
const LPSTR CWindow::APP_NAME = "Doodling";

#endif
  
Now, I have two .cpps that include this file: Window.cpp, and Doodling.cpp (don't ask.) When it comes time to build, I keep getting the following errors: Window.obj : error LNK2005: "public: static char * CWindow::APP_NAME" (?APP_NAME@CWindow@@2QADA) already defined in Doodling.obj Window.obj : error LNK2005: "private: static bool CWindow::s_IsFullScreen" (?s_IsFullScreen@CWindow@@0_NA) already defined in Doodling.obj Debug/Doodling.exe : fatal error LNK1169: one or more multiply defined symbols found I only declared and defined them once - in Window.h - so I can't figure out what it's talking about. Any help would be appreciated. [EDIT] Remembered to put in the sentinel so you know I have it -Normie "But time flows like a river... and history repeats." ... So...what about beaver dams? Edited by - normie on August 5, 2001 2:30:08 PM

Share this post


Link to post
Share on other sites
Aribu    122
I had a similar problem that went away when I initialized the class statics in the same file as the function definitions. I guess, in your case, that would be Window.cpp (or doodling.cpp.)

My guess is that they cannot be initialized until an instance has been created - which would be in the .cpp - since the statics are shared. This might help...

Share this post


Link to post
Share on other sites
Normie    122
Really? Well, damn, learn something new every day.

-Normie

"But time flows like a river... and history repeats."
...
So...what about beaver dams?

Share this post


Link to post
Share on other sites