Is it possible to concatenate variable/pointer names?
I have 5 pointers like:
pA0->SetWindowText("");
pA1->SetWindowText("");
pA2->SetWindowText("");
pA3->SetWindowText("");
I would like to use a loop to make it easier, something like:
for (i=0;i<4;i++)
{
(pA + i)->SetWindowText("");
}
Re: Is it possible to concatenate variable/pointer names?
Hello!
This is sadly not possible, but something like this:
void MySetWindowText(CWnd* pWnd)
{
pWnd->SetWindowText("My window text");
}
int main(void)
{
// a lot of code here
std::vector<CWnd*> vectorWindows;
vectorWindows.push_back(pA0);
vectorWindows.push_back(pA1);
vectorWindows.push_back(pA2);
vectorWindows.push_back(pA3);
std::for_each(vectorWindows.begin(), vectorWindows.end(), MySetWindowText);
// more code...
return(0);
}
Sincerely,
Wolfgang Petroschka (aka void*)
If this was an answer to a question, please rate it!!!
Re: Is it possible to concatenate variable/pointer names?
I don't know what class SetWindowText() is a member of, but lets say class X. Then:
X * pA[5];
memset(&pA[0], 0, sizeof(X *) * 5);
for (n = 0; n < 5; n++) {
pA[n] = new X;
if (pA[n]) {
pA[n]->SetWindowText("");
}
}
Hope this helps :-)
Re: Is it possible to concatenate variable/pointer names?
use like this,
for (i=0;i<4;i++)
{
*(pA + i)->SetWindowText("");
}
regards,
eswar