Skip to main content
GameDev.net gamedev.net
🔒 Locked

pass a vectorobject

Started by Edzio Sep 1, 2006 at 8:02 AM 2 replies 600+ views
Original Post
Edzio
Edzio
I am trying to pass a new "vector element" from a function back into a main vector of objects without using a pointer. The following code is the sub function that compiles but does not pass into the main vector d; where Dog is a class. void add_dog(vector& n) { string name; int age; cout << "name : "; cin >> name; cout << "age (1 - 12) : "; cin >> age; Baby new_dog(name, age, 0, 0, 0); new_dog.show_dog(); new_dog.temper(); /** b.push_back(new_dog); for (int i = 0; i < b.size(); i++) { b.show_dog(); } */ }
ToohrVyk
ToohrVyk
The vector is not modified in this function (because the only line that modified it is commented out). Aside from that, your approach is correct.
thallish
thallish
and in your description you are calling your vector d, in your arguments list you are calling it n and in the out commented part you are calling it b ;-)
regards/thallishI don't care if I'm known, I'd rather people know me
Edzio
Edzio
thanks ToohrVyk !! i got it ! knowing i was on the right track made a diferance! gamedev rocks!

Topic Locked

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

Sign in to reply to this topic.