J
jean.daniel.michaud
Hi,
I am using a class with operator() as threadfunc for Boost.Thread. I
have inheritance used with those class but it does not work, see the
example:
// Snippet on
#include <iostream>
#include <vector>
#include <boost/thread.hpp>
class Bird
{
public:
virtual void operator()() {std::cout << "a bird" << std::endl;}
virtual ~Bird() {}
};
class Swan : public Bird
{
public:
virtual void operator()() {std::cout << "a swan" << std::endl;}
};
int main()
{
Swan mySwan;
Bird* myBird = &mySwan;
Bird *b = &mySwan;
boost::thread thrd(*b);
thrd.join();
return 0;
}
// Snippet off
I would like to see "a swan" displayed, but I get "a bird"
instead... and for some reason I don't want to do that:
boost::thread thrd(mySwan);
As the member function is virtual, on call of operator () on the
object b (which is a swan) I should see Swan:
perator() called, no?
What it it I don't understand here?
Thanks and regards,
JD
I am using a class with operator() as threadfunc for Boost.Thread. I
have inheritance used with those class but it does not work, see the
example:
// Snippet on
#include <iostream>
#include <vector>
#include <boost/thread.hpp>
class Bird
{
public:
virtual void operator()() {std::cout << "a bird" << std::endl;}
virtual ~Bird() {}
};
class Swan : public Bird
{
public:
virtual void operator()() {std::cout << "a swan" << std::endl;}
};
int main()
{
Swan mySwan;
Bird* myBird = &mySwan;
Bird *b = &mySwan;
boost::thread thrd(*b);
thrd.join();
return 0;
}
// Snippet off
I would like to see "a swan" displayed, but I get "a bird"
instead... and for some reason I don't want to do that:
boost::thread thrd(mySwan);
As the member function is virtual, on call of operator () on the
object b (which is a swan) I should see Swan:
What it it I don't understand here?
Thanks and regards,
JD