c++ - Stack of polymorphed classes -


dear c++ professionals. got problem. have program, has 1 abstract class base_class , 2 derived classes: sippeers , dbget. has 2 threads. first thread gets commands user, second thread pocesses these commands. both derived classes represent different commands. so, have create kind of stack, should put user commands first thread , them in second thread process. make 1 stack commands, got use polymorphism. first, tried use std::list. there first problem: can't make list of abstract classes. tried use boost::ptr_list, there second problem: classes, created in first thread, dissappear end of procedure, created them. pointers become illegal. question: kind of realization should use? looks must store every copy of derived class. where?

an std::queue of shared_ptr<base_class> straightforward solution pass classes 1 thread without worring memory management. combined conditional variable signal queue not empty, consumer-thread can wait.

for polymorphism part, have virtual function (execute()?), consumer thread shouldn't aware class receives.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -