methinks i don't understand pointers

Started by
13 comments, last by Oxyacetylene 18 years, 10 months ago
Quote:Original post by Anonymous Poster
I posted a working example of a 3d array and a 3d vector there, and there are also some great comments in other posts.


Erm his not trying to make any kind of multidimensional array.

Advertisement
Okay, it's working!!! Actually, not really, the std::vector worked, it's just that I'm indexing past the extent of the vector. Thanks a whole lot everyone, consider yourself rated higher! :)
Quote:Original post by snk_kid
Erm his not trying to make any kind of multidimensional array.


But if he understands that example, he will understand pointers MUCH better.

David
Use the iterators if you want to go through a vector

vector<type>::iterator start = vectorObject.begin();
vector<type>::iterator end = vectorObject.end();

while(start != end){
cout << *start << endl;
start++;
}
start is a pointer to the first object in the vector, and end is 1 past the last object stored in the vector
Quote:Original post by evanofsky
Okay, I tried using an std::vector, and it still doesn't work:
for(int i = 0; i < num_objects; i++) {   Object* object;   Init_Object(&object);   list.push_back(object);}list->DoSomething(); // crashes



Does Init_Object take an Object*, or an Object**?

If it takes an Object*, then Init_Object(&object) is wrong. &object, is the address of the pointer, not the address stored in the pointer.

Remember Object*, is a pointer. Object** is a pointer to a pointer.

This topic is closed to new replies.

Advertisement