Static struct in a class

Started by
2 comments, last by Twisol 16 years, 10 months ago
I'm having a lot of problems with putting a static struct into my class. I read on cprogramming.com that static member variables needed to be defined outside the class definition, but I don't know how to do this for static structs. Here's my code right now.

#include <cstdlib>
#include <string>
#include <new>
#include <windows.h>

#define WIN32_LEAN_AND_MEAN

class ConsoleBase
{
	private:
		ConsoleBase();
		static bool exists;
		static ConsoleBase* CurrentBase;
		void* operator new(size_t size);

		static struct _ConsoleInfo
		{
			std::string title;
		} ConsoleInfo;

--------------> //This is that troublesome struct.

	public:
		~ConsoleBase();

		// Returns a ConsoleBase* pointer.
		// Remove with the delete operator
		static ConsoleBase* New();
		void operator delete(void* p);

		static void Title(std::string title);
};


Advertisement
You don't need to declare the struct as static.
Quote:Original post by santonel
You don't need to declare the struct as static.



ConsoleInfo is a static variable of type _ConsoleInfo, the struct is not declared static ... the variable is

You must add:
ConsoleBase::_ConsoleInfo ConsoleBase::ConsoleInfo;
outside of your class definition
where ConsoleBase::_ConsoleInfo is the type and ConsoleBase::ConsoleInfo the class member
Thanks, it worked. XP I kinda thought it meant to give it a value...

[Edited by - linkofazeroth on May 31, 2007 11:35:49 PM]

This topic is closed to new replies.

Advertisement