What is good practice to implement a set function for a class variable which is stored in a pointer (due to the need of polymorphism).
Do I pass a pointer to the set function or the object by reference? Also what is the textbook way of making sure no memory leaks exist? (Unfortunately, I can't use smart pointers.)
The way I see it I have two options:
class A {
B* b;
setB(B& newB) {
delete b;
b = &newB;
}
//vs:
setB(B* newB) {
delete b;
b = newB;
}
};