How to implement the factory method pattern in C++ correctly

后端 未结 11 1183
暗喜
暗喜 2020-11-22 14:55

There\'s this one thing in C++ which has been making me feel uncomfortable for quite a long time, because I honestly don\'t know how to do it, even though it sounds simple:<

11条回答
  •  旧时难觅i
    2020-11-22 15:13

    Factory Pattern

    class Point
    {
    public:
      static Point Cartesian(double x, double y);
    private:
    };
    

    And if you compiler does not support Return Value Optimization, ditch it, it probably does not contain much optimization at all...

提交回复
热议问题