Desperation with Boost Threads
Hello group,
I strongly hope this is on-topic here - I guess it's a language question
as Boost is more or less part of the C++ language (or at least it is a
candidate for getting into the standard). If I'm wrong here, please
point me to the correct location.
Basically I'm just trying to get a incredibly simple, stupid example to
work - and I can't. It doesn't compile:
#include <boost/thread.hpp>
class Thread {
private:
boost::thread ThreadID;
void operator()();
public:
Thread();
void Run();
virtual void Work() = 0;
virtual ~Thread();
};
Thread::Thread() {
}
void Thread::operator()() {
Work();
}
void Thread::Run() {
ThreadID = boost::thread(*this);
}
Thread::~Thread() {
}
I get a bunch of compiler errors that I'm not even close to understanding:
g++ -O2 -Wall -g -DTRACE -ICommon -c -o Thread.o Thread.cpp
/usr/include/boost/noncopyable.hpp: In copy constructor
???boost::thread::thread(const boost::thread&)???:
/usr/include/boost/noncopyable.hpp:27: error:
???boost::noncopyable_::noncopyable::noncopyable(const
boost::noncopyable_::noncopyable&)??? is private
/usr/include/boost/thread/thread.hpp:35: error: within this context
Thread.hpp: In copy constructor ???Thread::Thread(const Thread&)???:
Thread.hpp:6: note: synthesized method ???boost::thread::thread(const
boost::thread&)??? first required here
Thread.cpp: In member function ???void Thread::Run()???:
Thread.cpp:11: note: synthesized method ???Thread::Thread(const Thread&)???
first required here
Thread.cpp:11: error: initializing argument 1 of ???boost::function0<R,
Allocator>::function0(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value,
int>::type) [with Functor = Thread, R = void, Allocator =
std::allocator<boost::function_base>]???
Thread.cpp:11: error: cannot allocate an object of abstract type ???Thread???
Thread.hpp:6: note: because the following virtual functions are pure
within ???Thread???:
Thread.hpp:13: note: virtual void Thread::Work()
/usr/include/boost/noncopyable.hpp: In member function ???boost::thread&
boost::thread::operator=(const boost::thread&)???:
/usr/include/boost/noncopyable.hpp:28: error: ???const
boost::noncopyable_::noncopyable&
boost::noncopyable_::noncopyable::operator=(const
boost::noncopyable_::noncopyable&)??? is private
/usr/include/boost/thread/thread.hpp:35: error: within this context
[...]
What I want should be pretty clear: I want to be able to derive a class
from Thread to use it in such a fashion:
public mythread : public Thread {
mythread() : Thread() { }
void Work() {
while (true)
std::cerr << "Working..." << std::endl;
}
}
and then use it:
Thread x = mythread();
x.Run();
I want to use that abstraction so I can later on provide more
functionality (such as x.Abort() or such).
Can you tell me how to get that piece of code to compile? I'm desperate
after about two hours of fiddling with three lines of code :-\
Kind regards,
Johannes
--
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verl??sterung von Gott, Bibel und mir und bewusster Blasphemie."
-- Prophet und Vision??r Hans Joss aka HJP in de.sci.physik
<48d8bf1d$0$7510$5402220f@news.sunrise.ch>