I’ve been trying to implement a dynamically sized array of a derived component class using ScopedPointer<ScopedPointer> and have been running into all sorts of grief. After spending a rather embarrassing amount of time failing with the ScopedPointers I proved to myself I could do it quite easily with standard pointers. I’m still not sure why I couldn’t get ScopedPointers to work, but as an alternative to my shameful non-RAII implementation I had a couple of goes at implementing using OwnedArray instead.
As it happens, I was declaring the OwnedArray as a private member in my header file like so: “OwnedArray myVar;”
When I then attempted to initialise it in my constructor code with “OwnedArray myVar = new OwnedArray;” I got a compile error and so shortened it to “OwnedArray myVar;”. This compiled OK, but resulted in a run time error which was only resolved by removing this statement (i.e. second declaration).
So my questions of utter C++ noobness:
Why would the second declaration cause a run time error?[/]
Why don’t I need to initialise the OwnedArray before adding to it?[/]
Is there a good reason why I couldn’t used ScopedPointer<ScopedPointer> to do a similar thing?[/]
Thanks in advance,
PS - I’ve spent a number of hours reading tutorials and other documentation before resorting to asking here, I’m trying not to waste your time