Template argument deduction for class templates in C++17: am I doing it wrong?

我的梦境 提交于 2019-12-01 07:33:33

Class template argument deduction works for declaring instances of class types:

Derived d(42);

Or new-expressions:

auto p = new Derived(42);

Or function-style casts:

foo(Derived(42));

It does not work for declaring pointers.


You'll have to simply provide the template arguments as you've always had to. Or, I guess:

template <class T> Base<T>* downcast(Base<T>* p) { return p; }
auto pt_base = downcast(new Derived(42));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!