Skip to content

Instantly share code, notes, and snippets.

@paulocoutinhox
Created January 19, 2022 01:26
Show Gist options
  • Save paulocoutinhox/368f5c42f328adfde00057bed612f31d to your computer and use it in GitHub Desktop.
Save paulocoutinhox/368f5c42f328adfde00057bed612f31d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <memory>
using namespace std;
class Renderer
{
public:
int xyz = 99;
Renderer() {
cout<<"xyz const: " << xyz << endl;
}
};
class Context
{
public:
std::shared_ptr<Renderer> renderer;
std::size_t targetFrameDuration;
Context() : renderer(nullptr), targetFrameDuration(0) {}
~Context() {
std::cout << "Context was destroyed" << std::endl;
}
};
auto context = std::make_shared<Context>();
void createRenderer(const std::shared_ptr<Renderer> & renderer)
{
cout<<"create renderer 1" << endl;
renderer->xyz = 98;
context->renderer = renderer;
cout<<"xyz 1: " << renderer->xyz << endl;
cout<<"create renderer 2" << endl;
}
int main()
{
auto renderer = std::make_shared<Renderer>();
renderer->xyz = 97;
cout<<"xyz 2: " << renderer->xyz << endl;
createRenderer(renderer);
cout<<"xyz final: " << context->renderer->xyz << endl;
cout<<"Hello World" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment