0

I have an abstract (template) class tXmlNode from which I have derived the template class tXmlGeometry. This derived class shall be constructed with a pointer to an object of varying type hence it is created as a template. This object shall be transferred to the derived class via a pointer.

My current implementation of the constructor of the derived class is as follows (I leave out the scope implementation as it is not relevant to my question I think):

nXml::tXmlGeometry<Part>::tXmlGeometry(Part* part) : tXmlNode<Part>(part)

My compiler (MS VisualStudio 2019) accepts this. But it also accepts that:

nXml::tXmlGeometry<Part>::tXmlGeometry(Part* part) : tXmlNode<Part>(*part)

What is the exact difference here? As far as I understand it the second one calls the constructor of the abstract class and transfers the content of part to this tXmlNode constructor whereas the first one does what?

Now I am currently creating an abstract class tXmlSegment that inherits from tXmlGeometry.

The constructor for this new abstract class is formulated as follows:

nXml::tXmlSegment2D::tXmlSegment2D(tXmlGeometry<Part>* geo, const int npos) : tXmlGeometry<Part>(*geo), position(npos)

What is curious is that my compiler now insists of getting the dereferenced geo object and I don't understand the reason for that. Why is it so that I have to dereference it?

EDIT: The constructor of tXmlNode is as follows:

template<class Node>
    inline tXmlNode<Node>::tXmlNode(
        Node* node,
        const int npos) : xml_doc(nullptr), node(node), n_childs(0), n_attr(0), position(npos)
  • 1
    And what are constructor signatures for `tXmlNode()`? – alagner Mar 19 '21 at 09:08
  • 1
    `tXmlGeometry(*geo)` is using the copy constructor of your base – Caleth Mar 19 '21 at 09:10
  • @alagner: I've edited the post accordingly. – ManyQuestions Mar 19 '21 at 09:12
  • @Caleth: I am not sure if I implemented one. I've added the signature of the constructor of the base class. To my understanding it should call this one. – ManyQuestions Mar 19 '21 at 09:14
  • You either declare a copy constructor yourself, or the compiler implicitly generates one. – Caleth Mar 19 '21 at 09:15
  • 1
    @ManyQuestions try explicitly marking your copyconstructor as `delete`, you'll see ;) https://stackoverflow.com/a/38687106/4885321 edit: chart at the bottom of the post is what I'm explicitly pointing at. – alagner Mar 19 '21 at 09:16
  • Oh sh*t, I have never dealt with such constructors. :D I am learning C++ while writing... – ManyQuestions Mar 19 '21 at 09:17
  • @alagar: thanks for the link which is very instructive. However, I am still not sure why in one case it accepts both ```*part``` and ```part``` whereas in the other it only takes ````*part```. These classes are pretty similar, none have a user move or copy constructor as far as I understand this (and I don't understand much :D) – ManyQuestions Mar 19 '21 at 09:30

0 Answers0