Skip to content

Instantly share code, notes, and snippets.

@larsXYZ
Last active August 10, 2016 15:17
Show Gist options
  • Save larsXYZ/3ab2ea8196c6360d312fa030f2b4d42d to your computer and use it in GitHub Desktop.
Save larsXYZ/3ab2ea8196c6360d312fa030f2b4d42d to your computer and use it in GitHub Desktop.
Problem example
#pragma once
#include "parent.h"
struct child
{
void live(parent* p) { p->money -= 100; }
};
#pragma once
#include <vector>
#include "child.h"
struct parent
{
int money = 200000;
std::vector<child> children;
void life() { for (int i = 0; i < children.size(); i++) children[i].live(this); }
};
#include "parent.h"
#include <iostream>
int main()
{
parent Eric;
Eric.children.push_back(child());
Eric.children.push_back(child());
Eric.children.push_back(child());
Eric.children.push_back(child());
std::cout << Eric.money << std::endl;
Eric.life();
std::cout << Eric.money << std::endl;
system("PAUSE");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment