Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Factory for objects w/o default constructor (tmp?)

Thread Tools

Factory for objects w/o default constructor (tmp?)

Shawn McGrath
Posts: n/a
I'm writing a generic message handler system with two basic classes:
template <typename T>
struct MessageHandler //singleton-ized elsewhere
void publish(...);
void subscribe(MessageInterface<T> *);
void unsubscribe(MessageInterface<T> *);
std::vector<MessageInterface<T> *> vec;

and obviously:
template <typename T>
struct MessageInterface
void receiveMessage(const T *msg);

right now MessageHandler:ublish() looks like:
publish(T *msg) { std::for_each(vec... receiveMessage...);

This works fine, however it's up to the caller of publish() to create
the message. I'd rather put message creation inside the MessageHandler
class. The difficulty with doing that is not all T's will have a
default constructor.

I was looking into how boost::signals work, but that defines the
arguments at the time of handler class creation, and it's overall quite
confusing - is there a simpler way?

If not, can I apply the boost::signal method to make publish() a
template member function - if yes, is there a way to automatically
infer the template parameters based off the arguments? (ie so I don't
have to do:

message_handler.publish<int>( x );

and just have it know that I'm using publish<int> by the type of the
argument passed to publish())

Thanks a lot.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Abstract factory and Factory pattern C# ASP .Net 4 07-31-2008 03:22 PM
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
How to call default constructor from other constructor of the same class? C++ 9 03-06-2006 09:30 PM
Copy constructor hides default constructor Aire C++ 3 01-25-2004 05:47 PM
Abstract Factory or Factory Method pattern question.... Medi Montaseri C++ 17 09-03-2003 06:50 AM