Skip to main content
Rollback to Revision 1
Source Link
Cody Gray
  • 64.4k
  • 23
  • 197
  • 313

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?

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?

In 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?

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?

In 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?

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?

Source Link
user102937
user102937

In 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?