Private constructor,Static constructor

Discussion in 'C++' started by plmanikandan@gmail.com, Mar 3, 2006.

  1. Guest

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

    Rgds,
    Mani
    , Mar 3, 2006
    #1
    1. Advertising

  2. * :
    > Is static constructor available in C++?


    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.


    > Can anybody explain me about private and static constructors in c++


    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?
    Alf P. Steinbach, Mar 3, 2006
    #2
    1. Advertising

  3. wrote:
    > Is static constructor available in C++?


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


    Private constructor does exist and it is used to implement, for example,
    very popular design pattern "Singleton".

    > Rgds,
    > Mani
    >
    Aleksander Beluga, Mar 3, 2006
    #3
  4. Alf P. Steinbach wrote:
    > * :
    >> [..]
    >> Can anybody explain me about private and static constructors in c++

    >
    > A private constructor is private, only accessible to that class.
    >
    > There is no such thing as static constructor in C++.


    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
    Victor Bazarov, Mar 3, 2006
    #4
  5. * Victor Bazarov:
    > Alf P. Steinbach wrote:
    >> * :
    >>> [..]
    >>> Can anybody explain me about private and static constructors in c++

    >> A private constructor is private, only accessible to that class.
    >>
    >> There is no such thing as static constructor in C++.

    >
    > 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.


    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?
    Alf P. Steinbach, Mar 3, 2006
    #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. qazmlp
    Replies:
    19
    Views:
    789
    Daniel T.
    Feb 4, 2004
  2. baumann@pan
    Replies:
    4
    Views:
    2,769
    Rolf Magnus
    Apr 20, 2005
  3. Ricardo Palomares Martinez
    Replies:
    2
    Views:
    376
    david.karr
    Apr 28, 2007
  4. joes
    Replies:
    3
    Views:
    312
  5. Hicham Mouline
    Replies:
    5
    Views:
    2,366
    James Kanze
    Dec 19, 2008
Loading...

Share This Page