labs-edaf30/lab1/buggy_programs/leak.cc

30 lines
395 B
C++
Raw Normal View History

2021-10-27 15:15:47 +02:00
#include <iostream>
using std::cout;
struct Foo{
Foo(int s) :p{new int[s]} {}
int* p;
};
struct Bar{
Bar(int x) :f(x) {}
Foo f;
};
void example1()
{
Foo f(10);
{
cout << "entering inner block\n";
Bar b(20);
cout << "leaving inner block\n";
}
cout << "leaving example1\n";
}
int main()
{
example1();
cout << "leaving main\n";
}