3

I've got a task pool using threads which is trying to call a boost::function that happens to be purely virtual, without an implementation.

Is there anything like this?

void doStuff(boost::function<void()> foo) 
{
    if (!foo.pure_virtual) 
    {
        foo();
    }
}

Note: This isn't the same as foo.empty or if (foo) { }. The .empty API doesn't seem to detect the pure virtual-ness of the method.

bitcycle
  • 7,632
  • 16
  • 70
  • 121
  • 3
    Could you provide a concrete example of "boost::function that happens to be purely virtual"? – Igor R. May 01 '13 at 17:45
  • 2
    How did you manage to instantiate a class containing a pure virtual function? Sounds like you're calling `doStuff()` from somewhere you shouldn't be (for instance, from within a constructor or destructor of a class in the inheritance hierarchy). – Praetorian May 01 '13 at 17:57
  • 1
    A pure virtual points to null no? Another thing is you have to bind the function to an object, and that should not be possible with a pure virtual – Sebastian Zander May 01 '13 at 18:14

1 Answers1

-3

You cannot detect it, and you shouldn't have it in there in the first place!

ltjax
  • 15,837
  • 3
  • 39
  • 62
  • * Agreed that it shouldn't be happening in the first place. Thanks for the example. – bitcycle May 01 '13 at 18:53
  • 4
    "// This will not do virtual dispatch" --- this statement is false. Have you tried to run your code? – n. m. could be an AI May 01 '13 at 18:53
  • 4
    @bitcycle: this might be OK with you but the answer is built on a wrong assumption and is factually incorrect. `boost::bind(&Foo::f, &foo)(); ` **will** do virtual dispatch in this case. – n. m. could be an AI May 01 '13 at 18:54
  • 1
    Woa, I was sure it wouldn't dispatch virtually but you guys are correct! I removed the wrong bits. Would have deleted the answer, but can't since it's accepted. – ltjax May 02 '13 at 11:35