I am a beginner in C++, and got confused about the initialization of const pointers declared in headers. To give but one example, I have in my header a structure and a class like:
/* header file.h */
typedef struct A{ ... } A;
class myClass{
protected:
A *const myPtrA;
}
And would like to instantiate the content of myPtrA, for instance in a constructor, knowing that A is a quite complicated structure composed of substructures, and needs to be dynamically instantiated:
/* source file.cpp */
#include file.h
myClass::myClass() {
A *tmpA = new A;
*myPtrA = *tmpA;
}
Is this the good way to initialize my const pointer myPtrA? And to the extent each new call needs a dedicated delete call, can I delete my pointer tmpA immediately after the line *myPtrA = *a; without risk of losing the content pointed by myPtrA?
Thank you in advance for your time (and pardon my English ;) )
qroh