Your new array gets a pointer of a local variable (an element from the stack instead of from the heap). That variable gets destroyed and the pointer points to garbage. In fact, it points to some memory that will eventually hold other data and you will severly corrupt the program memory - unpredictable crash sooner or later...
Fix:
_bigChairs[_bigChiarsLength - 1] = new BigChair(name, color);
Is this a homweork assignment or an interview question? This is so basic.
Cheers
Andi
PS: use a suitable STL container (e.g. a
vector
) instead of a pointer of pointer. E.g.
std::vector<BigChair>
(or
std::vector<BigChair*>
, depends on you usage). The whole function would collaps to
mvVector.push_back(BigChair(name, color));
.