C# XML serialization of derived classes

[XmlInclude(typeof(Square))] public abstract class Shape {…} (repeat for all known subtypes) If the types are only known at runtime, you can supply them to the XmlSerializer constructor, but: then it is important to cache and reuse that serializer instance; otherwise you will haemorrhage dynamically created assemblies. It does this automatically when you use the constructor … Read more

How to avoid memory leaks when using a vector of pointers to dynamically allocated objects in C++?

std::vector will manage the memory for you, like always, but this memory will be of pointers, not objects. What this means is that your classes will be lost in memory once your vector goes out of scope. For example: #include <vector> struct base { virtual ~base() {} }; struct derived : base {}; typedef std::vector<base*> … Read more