473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Private constructor,Static constructor

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

Rgds,
Mani

Mar 3 '06 #1
4 5497
* pl**********@gmail.com:
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?
Mar 3 '06 #2
pl**********@gmail.com 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

Mar 3 '06 #3
Alf P. Steinbach wrote:
* pl**********@gmail.com:
[..]
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
Mar 3 '06 #4
* Victor Bazarov:
Alf P. Steinbach wrote:
* pl**********@gmail.com:
[..]
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?
Mar 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Andy | last post by:
1) Is there any use of defining a class with a single constructor declared in private scope? I am not asking a about private copy constructors to always force pass/return by reference. 2) Is...
4
by: baumann | last post by:
hi all, according the private / protected access control, - private; that is, its name can be used only by members and friends of the class in which it is declared. - protected; that is,...
1
by: Andrew Poulos | last post by:
I having some trouble understanding how to make functions private I have created an instance of an object using a constructor function and there are 4 prototypes: Comm = function() { //blah...
6
by: z_learning_tester | last post by:
Quick question- What happens if you have a private class with a public static method? Can you still say the following? Lets say you are making this call from another class, say class2... int...
2
by: Andrew Robinson | last post by:
I need to create a shared static field for use within a number of different classes. Which one should I be using or are they all really the same thing? public class Widget { private Widget() {}...
12
by: Preets | last post by:
Can anyone explain to me the exact use of private constructors in c++ ?
3
by: John Salmon | last post by:
g++ complains about illegal access to a private member when the following is compiled with a private copy constructor for the class C. When the copy constructor is public, the program runs and...
10
by: siddhu | last post by:
Dear Experts, I want to make a class whose objects can be created only on heap. I used the following approach. class ss { ss(){} public: void* operator new(size_t sz)
6
by: VSP | last post by:
Hello, I am just implementing singleton pattern in various ways. In one implementation I created a static member and returning that static member in the getInstance() function. I have made...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.