Topic: Pointer to member as template parameter
Author: jr@grenoble.hp.com (Jean-Rene Bouvier)
Date: Mon, 12 Dec 1994 08:10:35 GMT Raw View
I'd like to parametrize a template class with the name of a
member field of a parameter class. Here's an example:
template<class Object, Object* Object::*link>
class Queue {
// ...
};
For instance, this would allow to put an object on different
queues by specifying which Object pointer is to be used; given:
class Message {
public:
Message* globalNext;
Message* nextOnConnection;
// ...
};
We can now use 2 types of queues:
Queue<Message, &Message::globalNext> globalQ;
Queue<Message, &Message::nextOnConnection> connectionQ[NbrOfConnections];
The question is: is this legal in C++ (a pointer to some reference in the
ANSI standard would be appreciated, rather than a yes/no answer) ?
- jr bouvier