[ create a new paste ] login | about

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

aarbron - C++, pasted on Aug 13:
class Foo
{
public:
	std::string name;
	int index;
	
	Foo():name("Default"),index(-1)
	{
		std::cout<<"Foo "<<name<<" created\n";
	}
	~Foo()
	{
		std::cout<<"Destructor of Foo "<<name<<" of index "<<index<<std::endl;
	}
};

std::vector<Foo> foos;

void AddFoo()
{
std::cout<<"AddFoo called\n";
Foo tempfoo;
foos.push_back(tempfoo);
foos.back().name="Bob";
foos.back().index=foos.size()-1;
}

int main(int,char**)
{
	AddFoo();
	AddFoo();
	std::cout<<"End of program\n";
}


Output:
1
2
3
4
5
6
7
8
9
10
AddFoo called
Foo Default created
Destructor of Foo Default of index -1
AddFoo called
Foo Default created
Destructor of Foo Bob of index 0
Destructor of Foo Default of index -1
End of program
Destructor of Foo Bob of index 0
Destructor of Foo Bob of index 1


Create a new paste based on this one


Comments: