locked
Why Custom driver access sample make the Fx2Device class's constructor and deconstructor as an private method RRS feed

  • Question

  • i am fuzzy with why the sample make the Fx2Device class's constructor and deconstructor as an private method and give a public static method to call the constructor...what is the benefit?
    the code fragment as follow:
    Public ref class Fx2Device sealed
    {
       private:
        //.......
        Fx2Device(IDeviceIoControl* DeviceControl,String Id);
        ~Fx2Device();
      puculic:
        static FromId(String id);
    }
    
    hope some one could give me some hint.....thank you
    • Moved by Min ZhuMember Monday, March 4, 2013 2:13 AM C++ question
    Friday, March 1, 2013 7:49 AM

Answers

  • Hi,

    There are many scenarios for having private constructors. Few of them are:

    1. Restricting object creation
    2. For singleton patterns
    3. Restricting certain type of constructor (e.g. copy constructor, default constructor)

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jesse Jiang Thursday, March 7, 2013 2:06 AM
    Monday, March 4, 2013 4:31 AM