Search code examples
c++arraysdynamic-memory-allocationdefault-constructor

Dynamically allocating an array of objects fails


I'm able to create a dynamically sized array of integers like this:

int *cacheL2 = new int[L2/B2];

and I'm also able to create an object of type Data like this:

Data one(12,12);

and now I want a dynamically sized array of Data:

Data * vlaObj = new Data[L2/B2];

but it does not work...

Also, if you can tell me how to get hashes working for c++ that would be great. I was looking for examples, but everything just says #include "hash_map" however when I try to use the library it cant seem to find any of them.


Solution

  • #include <vector>
    
    // ...
    std::vector<Data> v;
    v.emplace_back( 12, 12 );