A Question about std::list

J

John

John Harrison said:
It's fine, why shouldn't it be? Do you think it contradicts something that
Richard or myself have already said? If so what? The rule about not being
able to reseat a reference when it has been initialised still applies.
Confused.

john

Thanks.
Each time the for loop in function1 is executed, a new v2 is declared
and refers to v1, right?
By the way, in function2, is the line-- v2.clear(), necessary?

Thanks again.

John
 
J

John Harrison

John said:
It's fine, why shouldn't it be? Do you think it contradicts something that
Richard or myself have already said? If so what? The rule about not being
able to reseat a reference when it has been initialised still applies.
Confused.

john

Thanks.
Each time the for loop in function1 is executed, a new v2 is declared
and refers to v1, right?[/QUOTE]

Right, except I would say created not declared, v2 is declared once only.
Each different time that v2 is created it can refer to a different object,
but within the same creation it always refers to the same object.
By the way, in function2, is the line-- v2.clear(), necessary?

If your function depends on the fact that v2 must refer to an empty vector
then it's good practice to empty it at the start of function rather then
relying on the caller of the function to always call with an empty vector.
On the other hand if all you are going to do is assign a whole new vector to
v2 (which is what your comments suggest) then it isn't necessary.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,938
Members
47,473
Latest member
pioneertraining

Latest Threads

Top