代码如下:
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
void funcx(boost::shared_ptr<int> c, int b) {
std::cout << "after: "
<< "&c " << static_cast<void *>(&c) << ", "
<< "c.get() " << static_cast<void *>(c.get()) << ", "
<< "&b " << static_cast<void *>(&b) << std::endl;
}
int main(int argc, char *argv) {
int a = 2;
int b = 3;
boost::shared_ptr<int> c = boost::make_shared<int>(a);
std::cout << "first: "
<< "&c " << static_cast<void *>(&c) << ", "
<< "c.get() " << static_cast<void *>(c.get()) << ", "
<< "&b " << static_cast<void *>(&b) << ", "
<< "&a " << static_cast<void *>(&a) << std::endl;
funcx(c, b);
system("pause");
return 1;
}
输出结果如下:
first: &c 003FF988, c.get() 004B0A04, &b 003FF998, &a 003FF9A4
after: &c 003FF444, c.get() 004B0A04, &b 003FF44C
请按任意键继续. . .