Quote:
I want to be able to turn off forces in a system without removing them, so I can turn them on later again. What are these things "lifetime and ownership" you talk of? I've never had any issues concerning them I don't think.
If you've ever used raw pointers, then:
(1) you've dealt with lifetime and ownership, or
(2) you have a memory leak or undefined behavior.
"Lifetime and ownership" refers to keeping track of who 'owns' a raw pointer and is responsible for its deletion. For example,
if you had pointers to the forces used on a particle in each particle object, it would be an error for the particle destructor to delete those pointers -- any pointer shared between more than one particle would be deleted twice. The ownership of the pointers should be in something else, perhaps the particle system object.
Quote:
Would I do this through a Linked List? I've never used them, only heard about them and read the Wikipedia article on them.
I mean you should not use the vector (floating point x, y, z) aspect of the force object to test for equality. Your BooleanForce objects have a pointer to a vector in them, which you use to test for equality. This is not exactly desirable, for a number of reasons(*). It would be better if you gave your forces some kind of non-pointer ID (such as an int) and used that as the identity test. You have less unnecessary raw pointers floating around in your system as a result.
In your system, it appears the only way I can ever remove a force or disable a force, or look up a force, is if I
already have that force. Because the lookup requires testing the force's 'force' Vector pointer against the pointer supplied to the function.
(*) In addition to the above, it implies a referential semantic when you probably only need a value semantic, and it does look like you have any kind of ownership management of the Vector pointer holding the force. Who allocates it? Who deletes it? This smacks of memory leak or undefined behavior waiting to happen, and if nothing else presents a clunky interface because the pointer does not appear to be necessary.