Skip to main content
gamedev.net
🔒 Locked

Pointer to a Vector?

Started by Sagar_Indurkhya Jul 11, 2004 at 7:59 PM 3 replies 300+ views
Original Post
Sagar_Indurkhya
Sagar_Indurkhya
Hi. I just want to know something(obviously :) I have a vector where person is a class with 2 functions and 3 variables. When I pass a vector to a function, which modifies the contents of the vector, do I need to pass it as a pointer/reference, or just as a value? I want to retain the modifications made. Thanks :-)
Chris Hare
Chris Hare
Yes (by non-const reference or pointer).
Sagar_Indurkhya
Sagar_Indurkhya
Ok. I did that. Now when I want to access things in the vector, I try using the operator, followed by the -> operator, but it says the vector has no such overload operator "->". Do I need to use an iterator? Thanx!
BigBadBob
BigBadBob
the problem you are getting is because by invoking operator[] you are accessing the actual vector element which is not a pointer. Therefore use the . operator to access members of the vector elements. only if your vector was vector would you use -> to invoke Person members.
Qw3r7yU10p!
Qw3r7yU10p!
struct SomeClass {    void Hello();};typedef std::vector<SomeClass> SomeClassCont;//container of SomeClass'esvoid SomeFunc(SomeClassCont& cont) {    for(int i = 0; i < cont.size(); ++i) {        cont.Hello();    }}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.