Advertisement

Linker problem with static member variables

Started by August 05, 2001 01:16 PM
2 comments, last by Normie 23 years, 6 months ago
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
I am a devout follower of the"Lazy Programmer's Doctrime"(tm)...and I'm damned proud of it, too!-----"I came, I saw, I started makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.
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...
Advertisement
Absolutely. Never define variables or functions (unless they''re inline functions) in header files. It won''t work.
Really? Well, damn, learn something new every day.

-Normie

"But time flows like a river... and history repeats."
...
So...what about beaver dams?
I am a devout follower of the"Lazy Programmer's Doctrime"(tm)...and I'm damned proud of it, too!-----"I came, I saw, I started makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.

This topic is closed to new replies.

Advertisement