我想知道爲什麼shared_ptr
沒有隱含的構造函數。它不會是暗示這裏的事實:Getting a boost::shared_ptr for this爲什麼shared_ptr有一個明確的構造函數
(我想出的原因,但認爲這將是一個有趣的問題張貼反正。)
#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 from `int*' to non-scalar type `
* boost::shared_ptr<int>' requested */
我不明白它是如何從根本上`d elete &foo;` – curiousguy 2011-10-07 14:40:40