'var' in class does not name a type

Hello, I'm trying to find out why this fails. I have searched internet without getting any useful info.

Part of my header file:

#include <deque>
#include <map>

class MessageStack
{
public:
static std::map<std::string, MessageStack*> *instances;
...
};

and in the cpp file:

#include "message_stack.h"

MessageStack::instances = new std::map<std::string, MessageStack*>();


But when compiling I get:
message_stack.cpp:22:15: error: ‘instances’ in ‘class MessageStack’ does not name a type
MessageStack::instances = new std::map<std::string, MessageStack*>();
^
Makefile:38: recipe for target 'message_stack.o' failed


Any solution on this?


PS: Sorry for not formatting the text but all the buttons for formatting messages here does not in Firefox... :(


Can we see the top of the include file. If the compiler does not have a definition for MessageStack, it might indicate a problem with preprocessor stuff.
message_stack.h is the header file as shown above. I just removed the member functions and non-static variables from the class MessageStack in this posting.

To avoid any misunderstanding, there is more of the file:

message_stack.h:
#ifndef MESSAGE_STACK_H_INCLUDED
#define MESSAGE_STACK_H_INCLUDED

#include <deque>
#include <map>

class MessageStack
{
public:
static std::map<std::string, MessageStack*> *instances;

private:
std::string name;
std::deque<std::string> messages;

private:
MessageStack(const std::string &name);

public:
void somePublicMemberFunctions();
};
#endif
Here is the top of the message_stack.cpp file (just in case):

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include "message_stack.h"

MessageStack::instances = new std::map<std::string, MessageStack*>();

MessageStack::MessageStack(const std::string &n)
{
name = n;
}
At last, I found the solution. The correct code in the cpp file was:

std::map<std::string, MessageStack*> *MessageStack::instances = new std::map<std::string, MessageStack*>;


Case closed :)
Topic archived. No new replies allowed.