I followed a number of posts on SO, and finally I can draw a conclusion that when we have something like :
Person name;
name
"Object" and "instance" are almost interchangeable. In C++, an object is formally any region of storage. "Instance" is not a formally defined term, but we typically refer to "instances of type X
", most commonly used with class types.
Foo f;
This declaration creates an object named f
. The object's type is Foo
. You could say the object f
is an instance of Foo
.
Your attempt to distinguish the terms was incorrect. The two things you've actually pointed out are two different ways of creating objects.
Person name;
In this case, we're creating an object name
of type Person
.
Person* name = new Person();
In this case, we're creating an object name
of type Person*
(pointer to Person
). We are also creating another object of type Person
using the expression new Person()
. This expression returns a pointer, which we are initialising the name
object with.