I am rewriting some code to eliminate global variables and made a class constructor/destructor handle cleanup of some third party library resources, but I am concerned about
Kind of. The rules is that the member variables are initialised in the order they are declared in the class declaration.
In your case, it is fine since device
is declared before document
.
However, in the following case, we have undefined behaviour, despite the order of the initialiser list.
class A {
public:
A(int i) : b(i), a(b) { }
private:
int a;
int b;
}
The members are initialized in the order they are declared, top to bottom
PoDoFo::PdfOutputDevice device;
PoDoFo::PdfStreamedDocument document;
PoDoFo::PdfPainter painter;
so it is safe to use device
to initialize document
.