ID:22933
 
I'm trying to develop a framework similar to BYOND's system of atoms and datums. I'm running into a problem with vectors and classes though. Right now I have an Atom class and a MovableAtom class. MovableAtom is a child of Atom. They both have an update() method which will update the properties and state of them each frame. Right now I have nothing to update for just an atom, but MovableAtom's need to move based on their velocity each frame. My problem is that I want a vector filled with all the atoms in my world, basically like "world.contents" in DM. I've defined my vector as a vector of atoms, but when I loop through them and call the update() method for each element, it calls it as though it were just an Atom, not a MovableAtom, even if I added it as a MovableAtom. Yes, I have called update() from the MovableAtom specifically, and it functioned properly. My problem lies in how I'm storing these in my vector, or perhaps this isn't the proper way to do this. If anyone is familiar with C++, perhaps you could point me in the right direction?
Could you please provide code as to how you're declaring the vector, the parent, and the child? And how you're calling the update method and such.
Also, the code on how you declared your update() method for each class could be useful.
Actually, I think I got it worked out. I declared my vector as pointers to Atoms instead of instances of Atoms now, and I used virtual methods to do the inheritance thing I'm trying to do. Thanks anyways though
Yep, you need to be very careful to make things virtual when you want them to be overloaded. And it's very rare that you'll actually want a vector of instances, unless that's the only context in which they're used; a vector of pointers or references is more common.