hi,

is it possible to declare constructors as private? if yes, will some one explain me how to do it or please provide some links regarding that.


thanks & regards
prasath

Recommended Answers

All 2 Replies

>is it possible to declare constructors as private?
Yes, and it provides some valuable functionality to do so occasionally.

>if yes, will some one explain me how to do it
Just place the constructor declaration in the private section rather than the public section:

class test {
public:
  test ( int init );
private:
  test();
};

In the test class, the single argument constructor is required by the outside world because it's the only one visible, but the implementation code of the test class can also use the default constructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.