C++ namespace examples

This commit is contained in:
Ryan Fleury
2024-04-01 11:11:27 -07:00
parent c45b12cfac
commit cfb34ec560
+46 -16
View File
@@ -1,30 +1,60 @@
struct Bar static int Static = 5;
namespace NS
{ {
int x; static int staticDataInNS = 99;
int y; struct A
int z; {
static int staticData;
int a = 20;
int b = 30;
void Foo()
{
Static += 1;
staticDataInNS += 1;
staticData++;
a++;
b++;
}
};
int A::staticData = 123;
}
struct Resource
{
int resourceType;
}; };
struct BarContainer struct Stack
{ {
Bar *bar; Resource *resource;
int bar_count;
int bar_cap;
}; };
struct Foo struct StackNode
{ {
BarContainer bar; StackNode *next;
int a; Stack v;
int b; };
int c;
struct Context
{
StackNode *entry_stack_first;
}; };
int main(void) int main(void)
{ {
Bar bar[100] = {0}; Resource r_ = {0};
Foo foo_ = {bar, 50, sizeof(bar)/sizeof(Bar)}; Resource *r = &r_;
Foo &foo = foo_; Stack s = {r};
StackNode n_ = {0, s};
StackNode *n = &n_;
Context c_ = {n};
Context *context = &c_;
// evaluate `context.entry_stack_first.v.resource.resourceType == 0xd8`
int x = 0;
NS::A a = {0};
a.Foo();
return 0; return 0;
} }