| 1 | 
 | 
|---|
| 2 | #include "boost/shared_array.hpp"
 | 
|---|
| 3 | #include <iostream>
 | 
|---|
| 4 | 
 | 
|---|
| 5 | struct B {};
 | 
|---|
| 6 | 
 | 
|---|
| 7 | struct D : public B {};
 | 
|---|
| 8 | 
 | 
|---|
| 9 | int main()
 | 
|---|
| 10 | {
 | 
|---|
| 11 | #if 1
 | 
|---|
| 12 |   boost::shared_array<int> pInt(new int[50]);
 | 
|---|
| 13 |   boost::shared_array<const int> pIntConst1(pInt);
 | 
|---|
| 14 |   boost::shared_array<int> pInt2;
 | 
|---|
| 15 |   pInt2 = pInt;
 | 
|---|
| 16 |   boost::shared_array<const int> pIntConst2(pIntConst1);
 | 
|---|
| 17 |   boost::shared_array<const int> pIntConst3;
 | 
|---|
| 18 |   pIntConst3 = pIntConst1;
 | 
|---|
| 19 | 
 | 
|---|
| 20 |   std::cout << "Use count: " << pInt.use_count() << std::endl;
 | 
|---|
| 21 | 
 | 
|---|
| 22 |   boost::shared_array<D> pD(new D[50]);
 | 
|---|
| 23 |   boost::shared_array<const D> pD2(pD);
 | 
|---|
| 24 |   std::cout << "Use count: " << pD2.use_count() << std::endl;
 | 
|---|
| 25 | #else
 | 
|---|
| 26 |   boost::shared_array<D> pD(new D[50]);
 | 
|---|
| 27 |   boost::shared_array<B> pB(pD);
 | 
|---|
| 28 | 
 | 
|---|
| 29 | #endif
 | 
|---|
| 30 |   return 0;
 | 
|---|
| 31 | }
 | 
|---|
| 32 | 
 | 
|---|