benefits of private or protected constructor

This is a discussion on benefits of private or protected constructor within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, I am thinking about the benefits of a private or protected constructor. The only benefits I could think ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    benefits of private or protected constructor

    Hello everyone,


    I am thinking about the benefits of a private or protected constructor. The only benefits I could think of is we could use singleton design pattern and make a public function (e.g. CreateInstance) as a single point to create instances and hide the constructor to outside.

    Any more comments?


    thanks in advance,
    George

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,295
    Quote Originally Posted by George2 View Post
    I am thinking about the benefits of a private or protected constructor. The only benefits I could think of is we could use singleton design pattern and make a public function (e.g. CreateInstance) as a single point to create instances and hide the constructor to outside.
    protected constructor prevents people from creating instances of a base class that is just an interface class and was never intended to be instantiated directly.
    But yeah you pretty much get the usefulness of it already.
    Last edited by iMalc; 11-03-2007 at 01:06 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C# and SQL
    By siten0308 in forum C# Programming
    Replies: 2
    Last Post: 07-09-2008, 12:34 PM
  2. webBrowser problem
    By algi in forum C# Programming
    Replies: 7
    Last Post: 08-19-2005, 09:35 AM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 09:48 AM
  4. two-argument constructor
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 06-13-2002, 11:35 AM
  5. Post programs
    By GaPe in forum C# Programming
    Replies: 8
    Last Post: 05-12-2002, 11:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21