Hello, For ease of reading, I've reformatted the previously posted message. I have the following simple code, but doesn't get compiled: #define DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(CLASS, VAR_PTR, CONDITION)\ boost::scoped_ptr auto__deletor__for__ ## VAR_PTR (\ boost::lambda::ret(boost::lambda::if_then_else(_1,\ VAR_PTR, static_cast(0)))(static_cast(CONDITION))) struct B { B() { std::cout << _T("\nCalling B::B()"); } ~B() { std::cout << _T("\nCalling B::~B()"); } }; bool processB(B *pb, bool consume) { if(consume) if(pb) { std::cout << _T("\nDeleting B by processB()"); delete pb; } return consume; } void test_selector() { bool consumed; B *pb1 = new B(); consumed = processB(pb1, true); // delete by processB DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(B, pb1, (! consumed)); B *pb2 = new B(); consumed = processB(pb2, false); // you do the job! DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(B, pb2, (! consumed)); } int main() { test_selector(); return 0; } Thanks for any help. B/Rgds Max ------------------------------------------------------------------- 新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )
AMDG Max wrote:
I have the following simple code, but doesn't get compiled:
#define DECLARE_PTR_AUTO_DELETOR_CONDITIONAL(CLASS, VAR_PTR, CONDITION)\ boost::scoped_ptr auto__deletor__for__ ## VAR_PTR (\ boost::lambda::ret(boost::lambda::if_then_else(_1,\ VAR_PTR, static_cast(0)))(static_cast(CONDITION)))
That's not the correct syntax for static_cast In Christ, Steven Watanabe
participants (2)
-
Max
-
Steven Watanabe