Re: template problem: local variable as non-type argument
vl106 <vl106@hotmail.com> writes:
I have to better describe the problem:
[kind of pseudo code]
void receive_message(int messageId, char* data) {
Base& new_message = Factory::createMessage(messageId, data); //
transition to C++
new_message.process();
}
From old, non-C++ library I receive messages identified by int id.
I want to map this "event" into an "object-oriented" message. Further
receive_message should stay stable. That is when a new kind of message
is received I only want to create a new specialization
(C<new_message_id>).
This specialization will have a process method with different
behaviour.
Why do you need a specialization? Why can't you just define a normal
class derived from Base? Once you're out of createMessage you can't
access the derived class anyway unless you know what it is.
I would just have createMessage do a lookup of ID to class to create,
either using a switch statement or a lookup table.
Anthony
--
Author of C++ Concurrency in Action | http://www.manning.com/williams
just::thread C++0x thread library | http://www.stdthread.co.uk
Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]