I created a vector with Pointers and I create new Objects from the class DigOut derived from Modul in one method called
BOOL Cbeckhoff_frontendDlg::OnInitDialog()
{
//...
std::vector<Modul*> arrDigOut;
arrDigOut.push_back(new DigOut(IDC_CHECK1, this,"GVL.DigOut1",pAddr));
//...
for(iNumDO = 0;iNumDO<1;iNumDO++) arrDigOut[iNumDO]->InitCheck(this);
//...
}
How can I access the vector from a different method like:
void Cbeckhoff_frontendDlg::OnBnClickedButton3()
{
for(iNumDO = 0;iNumDO<1;iNumDO++) arrDigOut[iNumDO]->SetID();
}
I thought about using public pointers or setters and getters,
but I don’t get to create membervariables like this:
std::vector<Modul*> * parrDigOut;
where it’s complaining, that Modul is not declared.
Your example gives the impression you are declaring the
vectorat function scope. Its lifetime ends at the end of the function call (and all memory is leaked). Store it as a class member and a member functionsbeginandendthat forward to thebeginandendmember functions of thevector. Possibly wrap them in adereference_iteratorto hide the fact that they are pointers.