Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created December 28, 2018 17:55
Show Gist options
  • Save miladvafaeifard/f278e512680ef460a202499f7cd96ff9 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/f278e512680ef460a202499f7cd96ff9 to your computer and use it in GitHub Desktop.
factory cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
enum class PointType {
cartesian,
polar
};
struct Point {
float x, y;
friend class PointFactory;
private:
Point(float x, float y): x(x), y(y) {}
};
struct PointFactory {
static Point newCartesian(float x, float y){
return {x, y};
}
static Point newPolar(float r, float theta){
return {
r * cos(theta),
r * sin(theta)
};
}
};
int main ()
{
auto p = PointFactory::newCartesian(2,3);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment