forked from albertz/playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-scope.cpp
More file actions
44 lines (36 loc) · 717 Bytes
/
test-scope.cpp
File metadata and controls
44 lines (36 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>
using namespace std;
struct Scope {
string name;
Scope(const string& n) : name(n) { cout << "Scope" << name << endl; }
~Scope() { cout << "~Scope" << name << endl; }
};
struct DoubleScope {
Scope scope1, scope2;
DoubleScope() : scope1("_d1"), scope2("_d2") { cout << "DoubleScope" << endl; }
~DoubleScope() { cout << "~DoubleScope" << endl; }
};
static int bar() {
Scope scope1("_bar1");
return 0;
}
static int foo() {
Scope scope1("_foo1");
{
DoubleScope dscope;
Scope scope2("_foo2");
}
Scope scope2("_foo2");
return bar();
}
int main() {
Scope scope1("1");
Scope scope2("2");
{
Scope scope3("3");
foo();
}
Scope scope4("4");
return foo();
}