ctor as protected

Discussion in 'C++' started by MJ, Aug 1, 2005.

  1. MJ

    MJ Guest

    Hi
    can I define constructor as protected??
    if yes than what are the implications and what is the diff bet defining
    the ctor as
    protected and public

    Mayur
     
    MJ, Aug 1, 2005
    #1
    1. Advertising

  2. MJ

    sachin Guest

    Defining c'tor protected or private means no body can instantiate it
    except the class derived from it.

    public c'tor class can be instantiated from any where in your code

    sachin
     
    sachin, Aug 1, 2005
    #2
    1. Advertising

  3. MJ

    Guest

    see Singleton and Factory in <<Desing patterns>> and you will
    understand when need to do that
     
    , Aug 1, 2005
    #3
  4. MJ

    Guest

    Public declaration of ctor allows all fuctions to acces it.If declared
    private or protected it is accessible only from the class itself or
    inherited classes respectively.

    Private or protected calss constructors are rarely used.
    one example is the implementation of singleton design patterns.

    Gevadas
     
    , Aug 1, 2005
    #4
  5. MJ

    BigBrian Guest

    > Defining c'tor protected or private means no body can instantiate it
    > except the class derived from it.


    Or static members of the class, or friends of the class.

    -Brian
     
    BigBrian, Aug 1, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Apricot
    Replies:
    4
    Views:
    556
    velthuijsen
    Apr 16, 2004
  2. NVH
    Replies:
    8
    Views:
    516
    mlimber
    Jul 6, 2006
  3. Grizlyk
    Replies:
    8
    Views:
    506
    Grizlyk
    Nov 29, 2006
  4. , India

    copy ctor vs default ctor

    , India, Aug 15, 2007, in forum: C++
    Replies:
    2
    Views:
    427
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Aug 15, 2007
  5. Anonymous
    Replies:
    2
    Views:
    389
    Victor Bazarov
    Aug 28, 2007
Loading...

Share This Page