samedi 24 juillet 2021

How does vector class takes multiple argument and create a array out of it?

vector example

vector<int> a{ 1,3,2 }; // initialize vectors directly  from elements
for (auto example : a)
{
    cout << example << " ";   // print 1 5 46 89
}
MinHeap<int> p{ 1,5,6,8 };    // i want to do the same with my custom class   

Any idea how to do accept multiple arguments in curly braces and form an array?

std::vector class uses std::allocator to allocate memory, but I do not know how to use this in a custom class. VS Code shows std::allocator

I have done the same but it does not work like that

template<typename T>
class MinHeap
{
    // ...
public:
    MinHeap(size_t size, const allocator<T>& a)
    {
        cout << a.max_size << endl;
    }
    // ...
};

noob here ....

Aucun commentaire:

Enregistrer un commentaire