Skip to content

Instantly share code, notes, and snippets.

@caiodanielnunessantos
Created June 12, 2020 00:49
Show Gist options
  • Save caiodanielnunessantos/540a45d216e8b3fd6937b13ab653e530 to your computer and use it in GitHub Desktop.
Save caiodanielnunessantos/540a45d216e8b3fd6937b13ab653e530 to your computer and use it in GitHub Desktop.
#include <vector>
class A;
class B;
class A {
std::vector <B*> list_of_b;
public:
A();
void MethodOfA();
};
class B {
long long element;
public:
B();
B* AddOne();
};
A::A() {}
void A::MethodOfA() {
std::vector <B*> _temp;
_temp.reserve(list_of_b.size());
std::for_each(list_of_b.begin(), list_of_b.end(), [_temp](B& pointer_to_b) {_temp.push_back(pointer_to_b->AddOne());});
}
B::B() {element = 1;}
B* B::AddOne() {
B* new_element = new B();
++(new_element->element);
return new_element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment