【发布时间】:2010-09-23 04:14:42
【问题描述】:
我想知道为什么shared_ptr 没有隐式构造函数。事实并非如此:Getting a boost::shared_ptr for this
(我找到了原因,但认为无论如何发布这个问题会很有趣。)
#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 */
【问题讨论】:
标签: c++ boost refcounting