Created
December 28, 2018 17:55
-
-
Save miladvafaeifard/f278e512680ef460a202499f7cd96ff9 to your computer and use it in GitHub Desktop.
factory cpp
This file contains hidden or 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 <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