keywords: C++, Foreach Operator Overload

Example:

class TestClass01
{
public:

    int ID;
};

class TestClass02
{
    //********* [foreach operator overload] begin **********
	
    const TestClass01* operator[](int Index) const
    {
        return Data[Index];
    }

    friend TestClass01** begin(const TestClass02& TC) { return TC.Data; }
    friend TestClass01** end(const TestClass02& TC) { return TC.Data + TC.Size; }
	
    //********* [foreach operator overload] end **********

    void AddElement(TestClass01* Element)
    {
        ...
        Data[Size] = Element;
        Size++;
    }
	
    ...

    TestClass01** Data;
    int Size;
};

int main(char* args, int argn)
{
    TestClass02 C2;

    for (TestClass01* C1 : C2)
    {
        C1->ID = 11;
    }
	
    return 0;
}

“Strategy is a commodity, execution is an art.” ― Peter Drucker