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

    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
    Friday, March 01, 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 07, 2013 2:06 AM
    Monday, March 04, 2013 4:31 AM