I have some code with a generic interface in which I need to cast up and down. I'm trying to convert to smart pointers now, but am running into some errors. The code below reproduces the problem. I'm using C++14, so I think this stuff is supposed to work automagically now?
#include <memory>
#include <iostream>
int main()
{
std::shared_ptr<int> a(new int);
*a = 5;
std::shared_ptr<void> b = std::dynamic_pointer_cast<void>(a);
std::shared_ptr<int> c = std::dynamic_pointer_cast<int>(b);
std::cout << *c; //should be 5
return 0;
}
However, when I try to compile this, I get:
Error C2680 '_Elem1 *': invalid target type for dynamic_cast
Error C2681 'int *': invalid expression type for dynamic_cast
Guessing I did something dumb in the syntax?