How i can delete a container from a deposit?

Hello.
I have a deposit of containers and i must delete the cats container. How i can do that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Cat
{
    string name;
    int age;
};

struct Pencil
{
    float sharpness;
    float length;
};

struct ListOfThings
{
    enum Type
    {
        CatList,
        PencilList
    } type;
    void *listData;
};

vector<Pencil> pencils;
vector<Cat> cats;
vector<ListOfThings> myThings;

int main()
{
    cats.push_back( {"Joey", 4});
    cats.push_back( {"Mitzi", 6});
    cats.push_back( {"Garfield", 10});

    pencils.push_back( {1.0f, 17.6f});
    pencils.push_back( {0.6f, 12.1f});
    pencils.push_back( {1.6f, 24.6f});
    pencils.push_back( {0.2f, 18.0f});

    myThings.push_back( {ListOfThings::CatList, &cats});
    myThings.push_back( {ListOfThings::PencilList, &pencils});

    for (const ListOfThings& list : myThings)
    {
        if (list.type == ListOfThings::CatList)
        {
            cout << "Ahh... A list of cats... curious...\n";
            for (const Cat& cat : *static_cast<vector<Cat>*>(list.listData))
{
              cout << cat.name << ", age: " << cat.age << '\n';

// here i must delete the cats container from myThinks

}
        }
        else if (list.type == ListOfThings::PencilList)
        {
            cout << "Hmm... A bunch of pencils...\n";
            for (const Pencil& pencil : *static_cast<vector<Pencil>*>(list.listData))
            {
                cout << "sharpness: " << pencil.sharpness << ", length: " << pencil.length << '\n';
            }
        }
    }
}
Last edited on
Yes i know that. But here in for loop must delete a container, no an object in front or end but the all container and then break the loop...
How from myThings erase cats container?
In practice from a deposit of containers, how i can erase a container if i know his name only?
Last edited on
Topic archived. No new replies allowed.