c++ - How to copy by value into a container class? -


I am writing a rare matrix class. I need a node class, which will be a template for its contents. My problem with writing this class is:

How do I store content?

I want to store the contents with value. If I store it by indicator and it should be destroyed, then I have trouble. How can I execute a copy in the setContents method safely? Does C ++ offer any guarantee that a class that should be placed in my node container has the ability to clone it?

I have seen in the copy maker but I have some scope, what if the implied class will not implement a copy constructor? It will not be wise to pass the node with reference, because the original object should be removed or out of the scope, because it can be linked.

What is the "Standard C ++" way of doing this?

The standard C ++ approach is to mandate that the type Must be copied (and probably assigned) This is a very reasonable requirement and is used by all container class templates in the standard library.

For underlying types and simple POD-types, user-declared per constructor is not usually necessary. An author of a class that is not as simple, but requires price sitetics, it is usually necessary to provide a suitable copy maker in any case.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -