[ create a new paste ] login | about

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

C++, pasted on Nov 21:
class Klass{
public:
	int *p;
	Klass(){ p=new int();}
	~Klass(){ delete p; }
};

class Manager{
public:
	Manager(){};
	~Manager(){};
	void add(const Klass &k){
		v.push_back(k);
	}
	const std::vector<Klass>& get(){ return v; }
private:
	std::vector<Klass> v;
};

int main(){
	Manager m;
	{
		Klass k;
		*k.p=20;
		m.add(k);
		std::cout << *(m.get()[0].p) << std::endl;
	}
	std::cout << *(m.get()[0].p) << std::endl;
} 


Output:
1
2
3
4
5
20
-1785358955
block freed twice

Exited: ExitFailure 127


Create a new paste based on this one


Comments: