ctor as protected

M

MJ

Hi
can I define constructor as protected??
if yes than what are the implications and what is the diff bet defining
the ctor as
protected and public

Mayur
 
S

sachin

Defining c'tor protected or private means no body can instantiate it
except the class derived from it.

public c'tor class can be instantiated from any where in your code

sachin
 
R

realfun

see Singleton and Factory in <<Desing patterns>> and you will
understand when need to do that
 
G

gevadas

Public declaration of ctor allows all fuctions to acces it.If declared
private or protected it is accessible only from the class itself or
inherited classes respectively.

Private or protected calss constructors are rarely used.
one example is the implementation of singleton design patterns.

Gevadas
 
B

BigBrian

Defining c'tor protected or private means no body can instantiate it
except the class derived from it.

Or static members of the class, or friends of the class.

-Brian
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top