A constructor other than the standard is required for this structure.

I have the following structin C ++, and I was wondering if I need to define a constructor different from it when I use it as follows:boost::shared_ptr<node> p_node = boost:shared_ptr<node>();

struct node
{
    std::string name;
    std::map<std::string, std::vector<variant> > values; // it is possible that nodes contain as a value, key/value pairs so we need a map

    NodeType type;  //Enum

    typedef struct attrib
    {
        std::string key;
        variant value;  //Boost::variant
    };

    std::vector<attrib> attributes;

    boost::shared_ptr<node> childnode;
};
+3
source share
3 answers

"this POD needs a custom constructor" ... what is a POD? POD does not contain complex objects such as lines and maps. POD means plain old data like paired and char arrays.

, , , - . std::map, std::vector std::string , . boost::shared_ptr NULL. attrib - , -, . NodeType , . ? , , - , undefined.

+4

, POD.

, ctor , undefined . , , , , boost::shared_ptr<node> p_node = boost:shared_ptr<node>(); , NULL ptr, boost::shared_ptr<node> p_node;

+2

1-) ( 0 1 n) , ++ .

, .

Node * x = new Node(); , [Read First Line Again].

, - . , ++, ++.

1 .

+1
source

Source: https://habr.com/ru/post/1779368/


All Articles