Why type is not required for smart pointer of type shared pointer? | Sololearn: Learn to code for FREE!

+1

Why type is not required for smart pointer of type shared pointer?

Hi AFIK, shared_ptr is a template class. To create object of that class , we need to specify type. Refer attached code and observe below line into print function: shared_ptr temp = head; why type node is not required like shared_ptr<node> ? I was expecting compiler error without type but it works fine.. How this is possible? https://code.sololearn.com/crYV1fiFiNPr/?ref=app

7/24/2021 3:33:13 PM

Ketan Lalcheta

1 Answer

New Answer

+4

Short answer: C++17. Longer answer: https://en.cppreference.com/w/cpp/language/class_template_argument_deduction