Private constructor,Static constructor

P

plmanikandan

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

Rgds,
Mani
 
A

Alf P. Steinbach

* (e-mail address removed):
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

Aleksander Beluga

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

Victor Bazarov

Alf said:
* (e-mail address removed):
[..]
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
 
A

Alf P. Steinbach

* Victor Bazarov:
Alf said:
* (e-mail address removed):
[..]
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++.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top