X
xz
I just wanna confirm my understanding about the differences between
the signatures as follows, which are called all in the same way:
void foo(Vertex a, Vertex b, Vertex c);
void foo(Vertex & a, Vertex & b, Vertex & c);
void foo(const Vertex & a, const Vertex & b, const Vertex & c);
In the first one, the function actually works on the local copies of
a, b and c. Whatever happens inside foo does not change anything in
the outside world.
In the second one, the function operates on the original copies of a,
b and c. Whatever foo does to a, b and c inside the function
immediately applies on the a, b and c in the outside world.
In the third one, the function operates on the original copies of a, b
and c. However it cannot change anything about a, b or c.
Is that always true, no matter how the copy-constructor of Vertex is
defined?
Basically, people use the first way when they need to only locally
change something of a, b, c but do not want that change influence the
original a, b, and c in the outside world.
People use the second way when they do want the changes to a, b, and c
apply to the original a, b, and c in the outside world. In this case,
a, b, c are actually like returned result.
People use the third way when they don't need to change anything about
a, b, and c in the function, i.e. they only read a, b, and c, and
meanwhile, they want to promote the memory-efficiency.
Is that understanding correct?
the signatures as follows, which are called all in the same way:
void foo(Vertex a, Vertex b, Vertex c);
void foo(Vertex & a, Vertex & b, Vertex & c);
void foo(const Vertex & a, const Vertex & b, const Vertex & c);
In the first one, the function actually works on the local copies of
a, b and c. Whatever happens inside foo does not change anything in
the outside world.
In the second one, the function operates on the original copies of a,
b and c. Whatever foo does to a, b and c inside the function
immediately applies on the a, b and c in the outside world.
In the third one, the function operates on the original copies of a, b
and c. However it cannot change anything about a, b or c.
Is that always true, no matter how the copy-constructor of Vertex is
defined?
Basically, people use the first way when they need to only locally
change something of a, b, c but do not want that change influence the
original a, b, and c in the outside world.
People use the second way when they do want the changes to a, b, and c
apply to the original a, b, and c in the outside world. In this case,
a, b, c are actually like returned result.
People use the third way when they don't need to change anything about
a, b, and c in the function, i.e. they only read a, b, and c, and
meanwhile, they want to promote the memory-efficiency.
Is that understanding correct?