if this is C++ why are you using pointers and malloc instead of
reference and new?