This statement:
int v = b->value();
The variable "b" is passed, like the Derived <int> object.
So tell the compiler:
int v = dynamic_cast<Derived<int>*>(b)->value();
Note. If b is not a <int> derivative, the result of the cast is NULL.
Therefore, it would probably be safer:
Derived<int>* d = dynamic_cast<Derived<int>*>(b);
if (d)
{
int v = d->value();
}
else
{
}
, , bad_cast:
Derived<int>& d = dynamic_cast<Derived<int>&>(*b);
int v = d->value();
, , .
int v = dynamic_cast<Derived<int>&>(*b).value();
, , boost:: any
int main()
{
boost::any b(5);
int v = boost::any_cast<int>(b);
b = 5.6;
double d = boost::any_cast<double>(b);
}