[ create a new paste ] login | about

Link: http://codepad.org/PXetOWlC    [ raw code | output | fork ]

C++, pasted on Sep 11:
#include <stdio.h>
#include <sstream>
#include <vector>
#include <list>


using namespace std;

list<int*> objList;

class CTest
{
public:
    CTest(){}
    ~CTest(){}

    void drawView();
};

class GLObject
{
public:
    GLObject(){}
    ~GLObject(){}

    void draw()
    {
        printf("-----------\n");
    }
};

void CTest::drawView() 
{
	static int prevSize = 0;
	static int size = 0;
	list< int* >::iterator obj_iterPos = objList.begin();
	list< int* >::iterator obj_iterEnd = objList.end();
 
	for (; obj_iterPos != obj_iterEnd; obj_iterPos++)
        {
		size = objList.size();
		if (size != prevSize) 
                {
                        printf("xxxx\n");
			obj_iterPos = objList.begin();
			obj_iterEnd = objList.end();
			prevSize = size;
		}
		if (((GLObject*)(*obj_iterPos)) != NULL) ((GLObject*)(*obj_iterPos))->draw();
	}
}

int main()
{
    GLObject * o1 = new GLObject();
    objList.push_back((int*)o1);

    GLObject * o2 = new GLObject();
    objList.push_back((int*)o2);

    GLObject * o3 = new GLObject();
    objList.push_back((int*)o3);

    CTest ct;
    ct.drawView();

    o3 = (GLObject *) objList.back();
    objList.pop_back();

    o2 = (GLObject *) objList.back();
    objList.pop_back();

    o1 = (GLObject *) objList.back();
    objList.pop_back();

    delete o3;
    delete o2;
    delete o1;

    return 0;
}


Output:
1
2
3
4
xxxx
-----------
-----------
-----------


Create a new paste based on this one


Comments: