Last active
May 31, 2021 22:49
-
-
Save markusbuchholz/78780b06a9188e5109cca32bf5f36554 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 <iostream> | |
#include <cstdlib> | |
#include <vector> | |
#include <algorithm> | |
#include <ctime> | |
#include <algorithm> | |
//---------------------------------------------------------------------- | |
struct Point3D | |
{ | |
int x; | |
int y; | |
int z; | |
}; | |
//---------------------------------------------------------------------- | |
Point3D *generatePoint3D() | |
{ | |
Point3D *p = new Point3D; | |
p->x = std::rand() % 100; | |
p->y = std::rand() % 100; | |
p->z = std::rand() % 100; | |
return p; | |
} | |
//---------------------------------------------------------------------- | |
int main() | |
{ | |
std::vector<Point3D *> galactix{5}; | |
std::generate(galactix.begin(), galactix.end(), generatePoint3D); | |
int ii{0}; | |
for (auto &i : galactix) | |
{ | |
std::cout << ii << " > " | |
<< " x: " << i->x << " y: " << i->y << " z: " << i->z << std::endl; | |
; | |
ii++; | |
} | |
} | |
/*--------------------------------------- | |
Expected output: | |
0 > x: 83 y: 86 z: 77 | |
1 > x: 15 y: 93 z: 35 | |
2 > x: 86 y: 92 z: 49 | |
3 > x: 21 y: 62 z: 27 | |
4 > x: 90 y: 59 z: 63 | |
----------------------------------------*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment