c++ - Why shared_ptr has an explicit constructor -


i wondering why shared_ptr doesn't have implicit constructor. fact doesn't alluded here: getting boost::shared_ptr this

(i figured out reason thought fun question post anyway.)

#include <boost/shared_ptr.hpp> #include <iostream>  using namespace boost; using namespace std;  void fun(shared_ptr<int> ptr) {     cout << *ptr << endl; }  int main() {     int foo = 5;     fun(&foo);     return 0; }  /* shared_ptr_test.cpp: in function `int main()':  * shared_ptr_test.cpp:13: conversion `int*' non-scalar type `  *  boost::shared_ptr<int>' requested */ 

in case, shared_ptr attempt free stack allocated int. wouldn't want that, explicit constructor there make think it.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -