On 01/19/2008 02:22 PM, Jon S. Berndt wrote in part: > .... Pushing an object instance onto a vector is a bad idea, as a proper > copy constructor must then be created,
Well ... that is exactly the point I'm trying to discuss. IMHO if you are going to write 23,000 lines of c++, it might be worth your trouble to figure out how to write a copy constructor. It ain't that tricky. You only need to figure it out once, and then you can use the technique over and over again. Actually you usually need four things: the basic constructor, the copy constructor, the assignment operator, and the destructor. Or just use something like ref_ptr. You might want to take a look at http://andesengineering.com/OSG_ProducerArticles/RefPointers/RefPointers.html which says in part: "the concept of reference counted objects will add years to your life in the long run." I am aware that JSBsim doesn't want to have an OSG dependence, but there are plenty of ways of having reference-counted objects without OSG dependence. C++ was invented for a reason. > We create instances of engines > and other components at runtime and place pointers to those objects in the > vector. Each object instance is [supposed to be] properly destroyed as the > sim shuts down. Computers are good at counting things. Why not let the computer keep track of the reference count? For example, stdlib lets you have strings, and then lets you have lists of strings, maps from strings to strings, et cetera. Stdlib does all the memory management so that the memory used by the string is freed when the last reference to the string goes away. Why not set it up so that we can have a std::list of engines? Reference-counted objects make that easy. It's not rocket science. I would say that pushing an object (such as an engine) onto a list is a good idea. A very good idea. C++ was invented for a reason. Switching from c-- to c++ does *not* consist of replacing malloc with new and replacing free with delete. Using automatic variables makes the code more reliable, and reduces the burden on those who want to read, debug, maintain, re-use, and/or extend the code. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel