You're allocating only an array of pointers of item *, you'll need to allocate the memory for each item also, e.g.:
struct item // naming it 'items' might be confusing, and was used inconsistently
// in your code sample
{
int member1;
int member2;
};
int N=5;
item **ptr=new item *[N];
for(int i = 0; i < N; ++i)
{
ptr[i] = new item();
}
Accessing your structure members looks like this:
ptr[2]->member1 = 42; // Sets member1 of the 3rd item element to 42
Note that you'll need to free the allocated memory somewhere as follows:
for(int i = 0; i < N; ++i)
{
delete ptr[i];
}
delete [] ptr;
I general for c++ you'd be better off using a c++ standard container like:
#include <vector>
int N = 5;
std::vector<item> myItems;
myItems.resize(N,item());
myItems[2].member1 = 42; // Sets member1 of the 3rd item element to 42
which would do all the memory management for you internally.
If you're using c++11 and do not need dynamically sized arrays you can even avoid heap allocated memory at all using std::array:
#include <array>
std::array<item,5> myItems; // Size is fixed to 5, you can't use a variable here
myItems[2].member1 = 42; // Sets member1 of the 3rd item element to 42
std::vector<item>orstd::vector<std::unique_ptr<item>>.