欢迎光临散文网 会员登陆 & 注册

智能指针

2023-04-08 01:45 作者:胖厨z  | 我要投稿

#include <iostream>

#include <string>

#include <memory>

#include <vector>

typedef std::shared_ptr< Tag > tag_ptr;

const tag_ptr func(int index, const std::vector< tag_ptr >& list)

{

    if (list.size() > index)

    {

        return list[index];

    }

    throw std::out_of_range("index");

}

int main()

{

     if (true)

    {

        std::vector < tag_ptr > test_vecotr = {};

        tag_ptr p;

        for (int i = 0; i < 10; i++)

        {

            p = std::make_shared< Tag >(i, std::to_string(i));

            std::cout << p << "|" << p->getValue() << std::endl;

            test_vecotr.push_back(p);

        }

        p = func(5, test_vecotr);

        std::cout << p << "|" << p->getValue() << std::endl;

    }

    return 0;

}

0000027FDC0EFE20|0

0000027FDC0EC720|1

0000027FDC0EC300|2

0000027FDC0ECFD0|3

0000027FDC102080|4

0000027FDC102C80|5

0000027FDC102C00|6

0000027FDC102E80|7

0000027FDC102B00|8

0000027FDC102980|9

0000027FDC102C80|5

Deallocate the memory 0

Deallocate the memory 1

Deallocate the memory 2

Deallocate the memory 3

Deallocate the memory 4

Deallocate the memory 5

Deallocate the memory 6

Deallocate the memory 7

Deallocate the memory 8

Deallocate the memory 9

Deallocate the memory LWPOLYLINE

Deallocate the memory LINE

Deallocate the memory CIRCLE

Deallocate the memory ARC

Deallocate the memory OBJECTS

Deallocate the memory ENTITIES

Deallocate the memory BLOCKS

Deallocate the memory TABLES

Deallocate the memory CLASSES

Deallocate the memory HEADER

Deallocate the memory EOF

Deallocate the memory ENDSEC

Deallocate the memory SECTION


智能指针的评论 (共 条)

分享到微博请遵守国家法律