Members - Reputation: 1041
Posted 21 October 2012 - 11:54 PM
I should mention that the "stuff" in question is mostly DirectX stuff.
Crossbones+ - Reputation: 4972
Posted 22 October 2012 - 12:39 AM
Problem is that (I guess) MSVC didn't implement proper exception throwing for a while, therefore making RAII much, much harder to use. Consider:
int *avoidPlainArraysWhenPossible = new int[RequiredValue()]; // (1)In old visual studio versions, new would return NULL on failure. Therefore at point (1)
- In compliant C++, you could just assume the array to be allocated
- In MSVC, you couldn't.
Those issues are pretty much resolved in 2010, but that's the likely reason for which they use Init calls instead of just relying on the ctor.
There's a complication however. Ctors cannot rely on internal virtual functions. That is, if your initialization is non-trivial, you cannot do RAII.
It is often possible in my experience to refactor those objects to not rely on virtual functions at construction by providing them with adeguate external support. But it takes effort.
Dtors are "worse" as they cannot be parametrized. The only way to provide them with reference to ... say Vertex Buffer managers... is to put a reference explicitly. This does not always makes sense.
For general code, your 1st choice should always be ctor/dtor only and pure RAII but this is just a sanity guideline. Alternatives are allowed and might make sense.