In C ++, ff I have a class that should contain an element that can be dynamically allocated and used as a pointer, or not:
class A {
type a;
};
or
class A {
A();
~A();
type* a;
};
and in the constructor:
A::A {
a = new type();
}
and destructor:
A::~A {
delete a;
}
Are there any advantages or disadvantages to one other than dynamic, requiring more code? Do they behave differently (except for the pointer to be dereferenced) or slower than the other? Which one should I use?
source
share