As a part of an exercise I need to built Drawing class that contains an array
of pointers to objects from other classes (different types of shapes)
I have a few problems with the constructor.
at first I tried:
but after the line: drawing_ = new pshape[n]; the program returns to main()Code:typedef shape* pshape;
...
Drawing(int n=10) :size_(n)
{
drawing_ = new pshape[n];
for (int i=0; i<n; i++)
drawing_[i] = new shape();
}
without entering the for loop;
so I tried this instead:
and this time it returns to main right after pshape* temp;Code:Drawing(int n=10) :size_(n)
{
pshape* temp;
temp = new pshape[n];
if (temp==NULL) exit(-1);
for (int i=0; i<n; i++)
{
temp = new shape();
if (temp[i]==NULL) exit(-1);
}
drawing_=temp;
}
what wrong with the code?