Numerator* ptr1 = &(num1 / den1); // perform the calculation(the divide operator is overloaded)
Denom* ptr2 = &den1;
Is this okay?
It depends...
- What will you do with ptr2? As long as ptr2 or any copy of it (e.g. passing to another function) does not outlive the scope of den1 you're good. If for instance, you return ptr2, and start dereferencing it outside of the scope of den1 you will have a funny behaviour as will be den1 out of scope and potentially destroyed, so you shouldn't reference its memory address anymore.
- ptr1 looks fishy to me. I'm not sure what the result of (num1 / den1) is, but if it's not an lvalue, you won't be able to take its memory address. A temporary object's address shouldn't be taken.
So it's up to you how you use it and whether you do something with it that you're not supposed to.
The pointers is to variable in the stack not heap so no need to delete them.
If your code receives a pointer, then your code shouldn't be responsible for destroying it, so it does not matter whether a pointer (an argument of your function) points to stack or heap, let the person/code who created it be responsible for releasing it.
Would it be better to make the pointer to Denom & Numerator objects shared_ptr since there are two pointers pointing to the same memory address?
Absolutely. Modern C++ should make use of std::shared_ptr to facilitate better pointer handling, help avoiding double-free or resource leakage.