Last active
August 10, 2016 15:17
-
-
Save larsXYZ/3ab2ea8196c6360d312fa030f2b4d42d to your computer and use it in GitHub Desktop.
Problem example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "parent.h" | |
struct child | |
{ | |
void live(parent* p) { p->money -= 100; } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); } | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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