I might have found my answer somewhere here, but nevertheless, I'd like to be sure.
I am making something represented in a graph (hence the nodes), and I wondered if this code of the constructors is working the way I think.
G++ doesn't complain.
I have the following class:
#ifndef viper_node
#define viper_node
#include "../globals.hpp"
#include <vector>
/**
* @brief The base class for the nodes
*/
class Node {
public:
/**
* @brief base constructor for the node
*/
Node();
/**
* @brief exteded constructor for the node
* @param [in] parent_p the pointer to the parent of the new node
*/
Node(Node*const& parent_p);
/**
* @brief extended^2 constructor for the node
* @param [in] parent_p the pointer to the parent of the new node
* @param [in] name the name of the node
*/
Node(Node*const& p, std::string const& name);
/**
* @brief base destructor
*/
~Node();
protected:
/// pointer to the parent node of this one (nullptr if rootnode)
Node* parent;
///pointers to the children
std::vector<Node*> children;
///the name of the class/func/var (ex: children)
std::string name;
///description of the name/func/var (ex: pointers to the children)
std::string description;
///the properties of the node (static, private,...)
uint flags;
/// the type of the node (function, variable, binary, etc.)
nodeType node_type;
///the scope of the node (global, class member, function local)
nodeScope scope;
unsigned long get_id() {return id;};
private:
///the id of the node (unique)
unsigned long id;
///to keep track of the next unused id
static unsigned long maxID;
};
#endif
and the following definitions:
#include "node.hpp"
unsigned long Node::maxID = 0;
Node::Node()
{
parent = nullptr;
flags = 0;
id = maxID++;
}
Node::Node(Node*const& parent_p) : Node::Node()
{
parent = parent_p;
}
Node::Node(Node*const& p, std::string const& Name) : Node::Node(p)
{
name = Name;
}
Node::~Node()
{
parent = nullptr;
for (auto it : children)
{
delete it;
}
}
My question is this:
If I call Node(parent_p,"name")
, is the function preceded by Node(parent_p)
which is itself preceded by Node()
?
Thanks for the help :-)