Effectively you are talking about a smart pointer class. The short answer is that VA already does this. I have two standard tests for this, that both work just fine for me.
One tests uses this variable:
boost::shared_ptr<testBoostPtrListbox> pTest;
and the second test uses this class:
template <class T>
class SmartPtr
{
public:
SmartPtr()
{
ptr = NULL;
RefCount = NULL;
}
int Attached() const
{
return ptr != NULL;
}
T &operator*()
{
return *ptr;
}
T *operator->()
{
return ptr;
}
const T *operator->() const
{
return ptr;
}
private:
T *ptr;
size_t *RefCount;
};
Lets start with the simple test. Can you add my class to one of your header files and then in the matching cpp file add this code:
class SimpleClass
{
public:
SimpleClass();
int one;
};
static void testSmartPointerArrayAccess()
{
Block< SmartPtr< SimpleClass > > SomeVariable;
int x = 0, y = 10;
for (x = 0; x < y; x++)
{
if (SomeVariable[x]->one)
{
// type -> before the semi-colon, and make sure that VA suggests
// "one" and "SimpleClass()"
SomeVariable[x];
}
}
}
A little more complex than the situation you are describing, but an easy place to start.