|
Boost Users : |
From: Jose Martinez (jmartine_1026_at_[hidden])
Date: 2008-05-03 08:42:32
OK I think I figured out the problem.
I think I did something stupid. I can't just take an undefined pointer and assign a number to the address it is pointing to.
class print{
int* count;
boost::asio::deadline_timer* t;
static int d_count;
public:
print (boost::asio::io_service& io, boost::asio::deadline_timer* timer)
: t(timer) {
d_count++;
std::cout<<"I'm in constructor: "<<*count<<" Addr of count:"<<count<<"\n";
*count = 0; // DO NOT DO THIS
I should have passed the value for count as an argument then assign its address to the member variable *count.
Like this:
class print{
int* count;
boost::asio::deadline_timer* t;
static int d_count;
public:
print (boost::asio::io_service& io, boost::asio::deadline_timer* timer, int *c)
: t(timer), count(c) {
d_count++;
std::cout<<"I'm in constructor: "<<*count<<" Addr of count:"<<count<<"\n";
The copy constructor would then look like this.
print (const print& p): t(p.t), count(p.count){++d_count;}
This matches with what Frank was saying about managing the state of operator()() outside of the object.
thanks!
jose
"survival first, then happiness as we can manage it"
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net