I have explained in the comments of this code my problem. The compiler complains that root
isn't initialized, however I initialize it in the brackets of the constructor. If I also used an initialization list
, then I would be initializing it twice instead of once ? How to design this properly ?
Tree.h
class Tree
{
public:
Tree();
~Tree();
private:
struct Node
{
Node(int i);
int i;
};
Node root;
};
Tree.cpp
#include "Tree.h"
Tree::Tree() // <---- Complains that root isn't initialized
/* An initialization list here fixes the problem, however
* that wouldn't be convinient because I need to calculate the arguments of
* the Node first... So if I used both an initializer list here
* and then I also initialize the root AGAIN in the brackets bellow,
* wouldn't I be executing more code for no reason ?
*/
{
root = Node(1); // initialize root
}
Tree::~Tree()
{ }
Tree::Node::Node(int i) :
{
i = 1;
}