Created
June 12, 2020 00:49
-
-
Save caiodanielnunessantos/540a45d216e8b3fd6937b13ab653e530 to your computer and use it in GitHub Desktop.
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 <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