Skip to content

Instantly share code, notes, and snippets.

@markusbuchholz
Last active May 31, 2021 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markusbuchholz/78780b06a9188e5109cca32bf5f36554 to your computer and use it in GitHub Desktop.
Save markusbuchholz/78780b06a9188e5109cca32bf5f36554 to your computer and use it in GitHub Desktop.
#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