|
Boost Users : |
Subject: [Boost-users] [proto] Object got sliced when passed by reference
From: Leon Sit (wing1127aishi_at_[hidden])
Date: 2011-03-11 16:57:04
Hi all
I have a class tree as the following
template<typename T>
struct base{
bool operator()(int i)const {
return static_cast< const T&>(*this)(i);
}
};
struct F1:public base<F1>{
bool operator()(int i) const{
return true;
}
};
struct F2:public base<F2>{
bool operator()(int i) const{
return true;
}
};
struct F3 :public base<F3>{
std::string junk_;
F3(std::string junk):junk_(junk){}
bool operator()(int i) const{
std::cout << junk_ << std::endl;
return false;
}
};
==================================================================
I am trying to use proto to derive the following systax
Predicate<F1> f1;
Predicate<F2> f2;
Predicate<F3> f3("hodqhoqw");
cout << ((f1||f2)&&f3)(1) << endl;
==================================================================
When proto get to the point of invoking the F3::operator(), the junk_
attribute got sliced away. I thought I am passing everything by constant
reference but the exception tells me otherwise. The full sample code is
attached, can someone tell me what I have missed? I am testing my code on
vc9 and vc10, and I am not using virtual function for performance issue.
Ultimately, I want to have the following syntax in the client code
F1 f1;
F2 f2;
F3 f3("hodqhoqw");
cout << ((f1||f2)&&f3)(1) << endl;
Thanks
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