#include

时间:2021-01-29 12:14:01

多个元素使用#include <boost/scoped_array.hpp>

单个元素使用#include <boost/scoped_ptr.hpp>

作用域数组

作用域数组的使用方式与作用域指针相似。关键不同在于,作用域数组的析构函数使用delete[]操作符来来释放所包含的对象。因为该操作符只能用于数组对象,所以作用域数组必须通过动态分配的数组来初始化。对应的作用域数组类名为boost::scoped_array,它的定义在boost/scoped_array.hpp里。

//error C2248: “boost::scoped_array<int>::scoped_array”: 无法访问 private 成员(在“boost::scoped_array<int>”类中声明)

 #include <iostream>
#include <boost/scoped_array.hpp> void main()
{
boost::scoped_array<int>p(new int[]); boost::scoped_array<int>pA(p);//error C2248: “boost::scoped_array<int>::scoped_array”: 无法访问 private 成员(在“boost::scoped_array<int>”类中声明)
}