【发布时间】:2011-03-18 06:52:45
【问题描述】:
我正在尝试使用共享指针调用带有普通指针参数的旧函数,但出现以下错误:
我试图通过一个简单的例子来表达我正在做的事情。我无法将参数更改为 display(),因为它在旧版中并且正在被许多其他模块使用。但是从我的函数中,我使用共享指针来调用 display。这是正确的吗 ?你能建议/建议吗?
#include <iostream>
using namespace std;
#include <boost/shared_ptr.hpp>
void display(int * x)
{
cout << endl << "Pointer value is = %x" << *x;
}
int main(){
boost::shared_ptr<int> ptr( new( int ) );
*ptr =5;
display(ptr);
return 0;
}
sh.cpp:在函数“int main()”中: sh.cpp:17:错误:无法将参数 '1' 的 'boost::shared_ptr' 转换为 'int*' 到 'void display(
【问题讨论】:
标签: c++