Boost logo

Boost :

Subject: [boost] tuple and virtual functions
From: Mark Snelling (mark_at_[hidden])
Date: 2012-01-12 08:30:10


I'm having a problem with Boost.Tuple virtual functions. Consider the code
below, I would have expected the output to be "B::foo()" but instead get
"A::foo()". Am I missing something here?

#include <boost/tuple/tuple.hpp>
#include <iostream>

class A
{
public:
virtual void foo()
{
std::cout << "A::foo()" << std::endl;
 }
};

class B :public A
{
public:
void foo()
 {
std::cout << "B::foo()" << std::endl;
}
};

boost::tuple< A > make( const A& a )
{
return boost::make_tuple( a );
}

int main( int argc, char* argv[] )
{
B b;
make( b ).get< 0 >().foo();

return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk