[lambda] instantiation in bind
In VC9.0 the following code gives the error message:
1>...\boost\tuple\detail\tuple_basic.hpp(419) : error C2259: 'Base' :
cannot instantiate abstract class
If the Base is not abstract, the code compiles and works as expected.
Unfortunately, I'm unable to realise why it tries to instantiate the
Base, and how to overcome this issue, so any enlightenment would be
greatly appreciated!
class Base
{
public:
virtual void close() = 0;
};
class Derived : public Base
{
public:
void close()
{}
};
#include
On Mon, Jul 20, 2009 at 7:24 PM, Igor R
In VC9.0 the following code gives the error message: 1>...\boost\tuple\detail\tuple_basic.hpp(419) : error C2259: 'Base' : cannot instantiate abstract class
If the Base is not abstract, the code compiles and works as expected. Unfortunately, I'm unable to realise why it tries to instantiate the Base, and how to overcome this issue, so any enlightenment would be greatly appreciated!
class Base { public: virtual void close() = 0; };
class Derived : public Base { public: void close() {} };
#include
typedef boost::shared_ptr<Base> BasePtr; typedef boost::shared_ptr<BasePtr> BasePtrPtr;
#include
#include namespace bl = boost::lambda;
BasePtrPtr makeHolder(Base *base) { return BasePtrPtr(new BasePtr(base), bl::bind(&Base::close, **bl::_1)); }
int main() { Base *b = new Derived(); makeHolder(b); return 0; }
The **bl::_1 (I suspect) results in a Base (eventually) rather than a Base& (which I guess is what you wanted). Using the fact that bind will take an object pointer (as opposed to an object/object reference), you can use this: return BasePtrPtr(new BasePtr(base), bl::bind(&Base::close, bl::bind(&BasePtr::get, bl::_1))); For some reason, *bl::_1 didn't want to compile. I'm making no guesses, so I just tried BasePtr::get, which I've used before (and compiles!) Stuart Dootson
AMDG Igor R wrote:
In VC9.0 the following code gives the error message: 1>...\boost\tuple\detail\tuple_basic.hpp(419) : error C2259: 'Base' : cannot instantiate abstract class
If the Base is not abstract, the code compiles and works as expected. Unfortunately, I'm unable to realise why it tries to instantiate the Base, and how to overcome this issue, so any enlightenment would be greatly appreciated!
This is a known bug. https://svn.boost.org/trac/boost/ticket/426 In Christ, Steven Watanabe
Thanks to both of you! The one thing I still don't understand is how comes that the virtual function is called correctly (in case of non-abstract base) - the error message looks like some object "slicing" should occur in this binder, shouldn't it?
AMDG Igor R wrote:
The one thing I still don't understand is how comes that the virtual function is called correctly (in case of non-abstract base) - the error message looks like some object "slicing" should occur in this binder, shouldn't it?
The error occurs in the return type deduction mechanism. There is no slicing at runtime. In Christ, Steven Watanabe
participants (3)
-
Igor R
-
Steven Watanabe
-
Stuart Dootson