Your first argument is not a reference, rather, its just a pointer. You have several problems in your code:
int main( int argc, char** argv ){ A* objectA; // <-- OBJECT NOT INITIALIZED, POINTER HAS GARBAGE DATA!!!! BuildObject( objectA, 3, 5.21f ); // <-- DOES NOT PASS IN POINTER REFERENCE PrintObject( objectA ); /* All went well so exit */ return 0;}
First initialize that pointer to NULL, else when you pass it in, it will be pointing to garbage. If you try to delete garbage, heap corruption errors will ensue. Secondly, you need to rewrite your builder function to something like this:
void BuildObject( A ** a_t, int iValue, float fValue ){ A *aPtr = *a_t; if(aPtr) { delete aPtr; aPtr = NULL; } aPtr = new A( iValue, fValue ); aPtr->SetBoolean( bValue );}int main( int argc, char** argv ){ A* objectA = NULL; // <-- INITIALIZED BuildObject(&objectA, 3, 5.21f ); // <-- PASS IN ADDRESS OF POINTER (A **) // And so on...}