T
Thomas Grund
Hi,
In the following code I would like that the class Node is only be used by
the class Database. So the idea was to make the interface protected and
use the friend definition. The code does not compile because the list
needs an public destructor. Making list<Node> a friend of Node doesn't
help. If the constructor and destructor in Node is moved to the public
section then everything works but this is not what I want.
Thanks a lot,
Thomas
#include <list>
using namespace std;
class Node
{
public:
protected:
Node(){};
~Node(){};
void addChild()
{
Children.push_back(Node());
}
private:
list<Node> Children;
friend class Database;
};
class Database
{
public:
void addItem()
{
n.addChild();
}
Node n;
};
int main()
{
Database d;
}
In the following code I would like that the class Node is only be used by
the class Database. So the idea was to make the interface protected and
use the friend definition. The code does not compile because the list
needs an public destructor. Making list<Node> a friend of Node doesn't
help. If the constructor and destructor in Node is moved to the public
section then everything works but this is not what I want.
Thanks a lot,
Thomas
#include <list>
using namespace std;
class Node
{
public:
protected:
Node(){};
~Node(){};
void addChild()
{
Children.push_back(Node());
}
private:
list<Node> Children;
friend class Database;
};
class Database
{
public:
void addItem()
{
n.addChild();
}
Node n;
};
int main()
{
Database d;
}