I am writing a sparse matrix class. I need to have a node class, which will be a template for its contents. My issue in writing this class is:
How do I store the contents?
I want to store the contents by value. If I stored it by pointer and it should be destroyed, then I'd have trouble. How can I safely perform a copy in the setContents method? Does C++ offer any guarantees that a class that should be placed into my node container has the capability to clone itself?
I've looked into the copy constructor, but I have some qualms. What if the contained class does not implement a copy constructor? Then passing it to the node by reference would not be wise, since that could lead to a dangling reference if the original object should be deleted or go out of scope.
What is the sort of "standard C++" way of doing this?