Skip to main content

In C++, I can declare a field 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?

user102937