In C++,c++ I can declare a field as a regular variable of some type, instantiate it in the constructor, and use it later:
private: Foo field;
...
A::A() {
field = FieldImpl();
}
....
method(field);
Or alternatively, I can use a pointer:
private: Foo* field;
...
A::A() {
field = new FieldImpl();
}
A::~A() {
delete field;
}
...
method(*field);
When declaring a field, how do I decide if I should use a pointer or a regular variable?