Templates, nested classes and static members

G

Guest

Hi!
I've just read the Multicast-Observer = Typed message article and
implemented the template at the end of the article. The implementation
looks like this:

#include <list>

template<typename T>
class Message
{
public:
class MessageReceiver
{
public:
virtual void process(const T& message) = 0;
};

...

typedef std::list<MessageReceiver*> MessageReceiverList;
private:

static MessageReceiverList m_messageReceivers;
};

template<typename T>
Message<T>::MessageReceiverList Message<T>::m_messageReceivers;

For some reason I get an compile error at the last line, the defintion
of the static member. Any ideas why?

/M
 
V

Victor Bazarov

I've just read the Multicast-Observer = Typed message article and
implemented the template at the end of the article. The implementation
looks like this:

#include <list>

template<typename T>
class Message
{
public:
class MessageReceiver
{
public:
virtual void process(const T& message) = 0;
};

...

typedef std::list<MessageReceiver*> MessageReceiverList;
private:

static MessageReceiverList m_messageReceivers;
};

template<typename T>
Message<T>::MessageReceiverList Message<T>::m_messageReceivers;

For some reason I get an compile error at the last line, the defintion
of the static member. Any ideas why?

No. If I take your code, remove the '...' and then compile it, I don't
get any error message. So, what message? Care to post code without
'...'?

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top