Private constructor,Static constructor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • plmanikandan@gmail.com

    #1

    Private constructor,Static constructor

    Is static constructor available in C++?
    Can anybody explain me about private and static constructors in c++

    Rgds,
    Mani

  • Alf P. Steinbach

    #2
    Re: Private constructor,Sta tic constructor

    * plmanikandan@gm ail.com:[color=blue]
    > Is static constructor available in C++?[/color]

    No, but you can achieve the same effect by representing your static data
    members as a single object of a class with a default constructor.

    [color=blue]
    > Can anybody explain me about private and static constructors in c++[/color]

    A private constructor is private, only accessible to that class.

    There is no such thing as static constructor in C++.

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?

    Comment

    • Aleksander Beluga

      #3
      Re: Private constructor,Sta tic constructor

      plmanikandan@gm ail.com wrote:[color=blue]
      > Is static constructor available in C++?[/color]

      No, it doesn't make any sense. Do you need your class to be prohibited
      from creating more than one time?[color=blue]
      > Can anybody explain me about private and static constructors in c++[/color]

      Private constructor does exist and it is used to implement, for example,
      very popular design pattern "Singleton" .
      [color=blue]
      > Rgds,
      > Mani
      >[/color]

      Comment

      • Victor Bazarov

        #4
        Re: Private constructor,Sta tic constructor

        Alf P. Steinbach wrote:[color=blue]
        > * plmanikandan@gm ail.com:[color=green]
        >> [..]
        >> Can anybody explain me about private and static constructors in c++[/color]
        >
        > A private constructor is private, only accessible to that class.
        >
        > There is no such thing as static constructor in C++.[/color]

        Potentially what the OP meant was the "factory method". A static
        member that makes an object and returns a pointer (reference) to it.
        Private c-tor goes hand in hand with that.

        V
        --
        Please remove capital As from my address when replying by mail


        Comment

        • Alf P. Steinbach

          #5
          Re: Private constructor,Sta tic constructor

          * Victor Bazarov:[color=blue]
          > Alf P. Steinbach wrote:[color=green]
          >> * plmanikandan@gm ail.com:[color=darkred]
          >>> [..]
          >>> Can anybody explain me about private and static constructors in c++[/color]
          >> A private constructor is private, only accessible to that class.
          >>
          >> There is no such thing as static constructor in C++.[/color]
          >
          > Potentially what the OP meant was the "factory method". A static
          > member that makes an object and returns a pointer (reference) to it.
          > Private c-tor goes hand in hand with that.[/color]

          Yes, I think you're right. However, let's point out that "static
          constructor" is a relatively standard term in software engineering,
          because it does exist in a number of languages. But not in C++.

          --
          A: Because it messes up the order in which people normally read text.
          Q: Why is it such a bad thing?
          A: Top-posting.
          Q: What is the most annoying thing on usenet and in e-mail?

          Comment

          Working...