and first of all, thanks to any people that can help me. I am currently working on a XML parser. Here is what I had not so long ago :
class Root
{
// bla bla
}
The Root is the first item of a linked list. It has a pointer to the first item, and function to add and remove item from the list.
class Base
{
// bla bla
}
The Base class is an simple Item, with a Pointer to the next item.
class Child : public Base
{
// bla bla
};
The Child class is derived from the Base class, and contains data (such has name and values for the elements and the attributes of my XML file).
class Derived_1 : public Child
{
// bla bla
};
class Derived_2 : public Child
{
// bla bla
};
The Derived class are my Attributes and my Elements. the Elements contains Root for a list of Attributes, and another for a list of elements (so i can build a hierarchy).
My base class need to contain the function of the Root, but can't inherit them as a child. So we "friend" the Root function in the Base class.
class Base
{
friend class Root
// bla bla
}
Recently, we spoke about the templates, and had to integrate them in the XML parser. So, first, we transformed the Root class in a template. As a consequence, The Root being used for the two Derived class, the Base class was affected this way :
template< class T >
class Root
{
// bla bla
}
-------------
class Derived_1;
class Derived_2;
class Child;
class Base
{
friend class Root<Derived_1>
friend class Root<Derived_2>
friend class Root<Child>
// bla bla
}
-------------
class Child : public Base
{
// bla bla
};
Until now, no problem. We had to forward declare the Derived class to avoid a loop in the includes. Then, we had to make the Base class a template, so we had :
class Derived_1;
class Derived_2;
class Child;
template< class T >
class Base
{
friend class Root<Derived_1>
friend class Root<Derived_2>
friend class Root<Child>
// bla bla
}
-------------
class Child : public Base<Child>
{
// bla bla
};
And then, the problem showed up, we had the make the Child class a template, so it became :
template< class T >
class Child : public Base<T>
{
// bla bla
};
However, the forward declaration in the Base class is not good anymore, and the way we declare friend class neither. I have to find a way to forward declare the Child class, but I can't see how. Until now, i didn't have any difficulties with it, but here, I don't see the logic behind it. Can someone please explain to me the way things work here (I do not ask for an answer were I just have to copy/past what you tell me, but I want to understand what's going on. thanks a lot for any help.