On 30 Mar, 15:54, Obelix <Obe...@asterix.gawrote:
GavinDeaneha scritto:
On 30 Mar, 15:03, Obelix <Obe...@asterix.gawrote:
CHeader(const CXML *pHead) : pXml(pHead) {};
ok. an digit error
But, if I would like to not declare pXml as const.... Have someone any idea ?
Fix the above error, which has nothing to do with const. After that
then if you remove const from the declaration of pXml then you will
also have to remove const from the declaration of pHead in the
constructor argument list. This makes sense - if pXml is a pointer to
non-const data, then you wouldn't ever want to initialise a CHeader
with a pointer to a const object.
that's ok. But, If I pass a non const pointer to a class method, is there a
probability that pHead is wrong or not ? In any case can I consider pHead right,
or sometime, pHead can assume a corrupt state ?
I'm not sure this answers your question, but ...
pHead is just a parameter of the constructor. After the constructor
finishes, pHead no longer exists. Presumably you are only ever going
to pass a pointer to a valid CXML object (or a null pointer if your
design allows for that) to the CHeader constructor.
pXml is private data within the CHeader object, so is under the
complete control of the object.
However, somewhere there must be a CXML object that pHead, and
therefore pXml, point to. The CXML object itself lives outside the
CHeader class so other parts of your program must have access to it.
In principle, the CXML object can be changed or destroyed without the
CHeader object knowing. It is up to you as the designer of this
program to make sure that anything that happens to the CXML object
does not cause any of the uses of the CHeader object to break.
Gavin Deane