The program as follows compiles fine in C++20:
#include <memory>
struct A{ virtual ~A() = default; };
struct B: A {};
int main()
{
std::shared_ptr<A> p = std::make_shared<B>();
auto x = dynamic_pointer_cast<A>(p);
}
But in C++17 it produces an error:
<source>: In function 'int main()':
<source>:9:14: error: 'dynamic_pointer_cast' was not declared in this scope; did you mean 'std::dynamic_pointer_cast'?
9 | auto x = dynamic_pointer_cast<A>(p);
| ^~~~~~~~~~~~~~~~~~~~
| std::dynamic_pointer_cast
In file included from /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/memory:77,
from <source>:1:
Could you please tell me what has changed in C++20 to make it work?
language-lawyer
tag on this question. – Umewarning: use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension [-Wc++20-extensions]
– Disrate