0

I hope somebody can help me to understand why I cannot access certain members of my abstract base class tXmlNode. I've searched StackOverflow and the net and could not really identify why it's not working. Admittingly I am pretty new to C++.

So here is a shortened code of my abstract base class

    template<class Node>
    class tXmlNode
    {
    public:
        tXmlNode();
        tXmlNode(Node* node, const int npos = 1);

        tXmlNode(const tXmlNode& rhs);  //copy constructor
        tXmlNode(tXmlNode&& rhs); //move constructor

        tXmlNode& operator=(const tXmlNode& rhs); //assignment operator
        //need to do move assignment operator. Not an issue at this stage.

        virtual ~tXmlNode();

        pugi::xml_node GetNode();

        int GetChildNumber();

    protected:
        Node* node;

        pugi::xml_node this_node = pugi::xml_node();
        pugi::xml_node parent_node = pugi::xml_node();

        int n_childs;
        int position;
    }
    ;

I derive several classes from this one, some of them themselves abstract classes.

A shortened version of my tXmlGeometry<Part> class:

    template<class Part>
    class tXmlGeometry : public tXmlNode<Part> 
    {
    public:
        tXmlGeometry();
        tXmlGeometry(Part* part);

        ~tXmlGeometry();

        pugi::xml_node GetParentNode();

    protected:
        std::string parent_id;
    };

From my base class I also derived another abstract class tXmlSegment2D:

    template<class Part>
    class tXmlSegment2D : public tXmlNode<tXmlGeometry<Part>>
    {
    public:
        tXmlSegment2D();
        tXmlSegment2D(tXmlGeometry<Part>* geo, const int npos);

        virtual ~tXmlSegment2D();

        std::string GetSegmentType();

    protected:
        std::string segment_type;
    }
    ;

from which I further derive my tXmlStraightLine class:

    template<class Part>
    class tXmlStraightLine : public tXmlSegment2D<Part>
    {
    public:
        tXmlStraightLine(tXmlGeometry<Part>* geo, const int npos);
        ~tXmlStraightLine();    
    }
    ;

The implementation of this class is as follows:

template<class Part>
inline nXml::tXmlStraightLine<Part>::tXmlStraightLine(
    tXmlGeometry<Part>* geo,
    const int npos) : tXmlSegment2D(geo, npos)
{
    this->position = 0;

    parent_node = geo->GetNode();

}
;

template<class Part>
inline nXml::tXmlStraightLine<Part>::~tXmlStraightLine()
{
}
;

So what is really weird is that I get an error message for tXmlStraightLine such as that parent_node qualifier could not be found. It doesn't complain about position though.

I thought maybe the grandchild "tXmlStraightLine" cannot take directly from its grandparent. But I've made something similar already which works and I cannot find why that latter works and this one doesn't.

(I have an abstract class class tXmlPart : public tXmlNode<tXmlCaseDefinition> and class tXmlShape : public tXmlPart, this lineage works fine. For completeness: class tXmlCaseDefinition : public tXmlNode<tXmlCaseDefinition>).

  • 2
    You need to provide a [mcve] and the full error message. – super Mar 24 '21 at 18:14
  • If you are not familiar with the concept, make a code example that I can copy-paste into a compiler and get the same error you get. – super Mar 24 '21 at 18:19
  • Are you sure this `parent_node` is not a misspelling for `parent_id` or the `node` field which is in the parent? – LBald Mar 24 '21 at 18:21
  • I am working on a minimum example. Knowing that the present code took me 3 months to elaborate it will take a lot of time but of course you are right to ask me that. Meanwhile I found a way to fix my issue :D I've put "this->" to the faulty lines. Now I no longer get an error message. Still have to test the code though. Please let me know if you think I should still provide some minimum example for others. Otherwise I think we can close this one. Sorry for that. I didn't know that ```this->``` is really so decisive 8O – ManyQuestions Mar 24 '21 at 19:13

0 Answers0