Jump to content
  • Advertisement
Sign in to follow this  

Static struct in a class

This topic is 4162 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'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>


class 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.


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

		static void Title(std::string title);

Share this post

Link to post
Share on other sites
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

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!