Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > ctor as protected

Reply
Thread Tools

ctor as protected

 
 
MJ
Guest
Posts: n/a
 
      08-01-2005
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

 
Reply With Quote
 
 
 
 
sachin
Guest
Posts: n/a
 
      08-01-2005
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

 
Reply With Quote
 
 
 
 
realfun@gmail.com
Guest
Posts: n/a
 
      08-01-2005
see Singleton and Factory in <<Desing patterns>> and you will
understand when need to do that

 
Reply With Quote
 
gevadas@gmail.com
Guest
Posts: n/a
 
      08-01-2005
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

 
Reply With Quote
 
BigBrian
Guest
Posts: n/a
 
      08-01-2005
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reference to pointer used in ctor (using 'this' in ctor) Anonymous C++ 2 08-28-2007 01:10 PM
copy ctor vs default ctor subramanian100in@yahoo.com, India C++ 2 08-15-2007 10:49 AM
ctor/dtor calls and ctor init seq Grizlyk C++ 8 11-29-2006 06:35 AM
Templates, copy ctor and type-conversion ctor NVH C++ 8 07-06-2006 07:19 PM
three times copy ctor called, one ctor called, why? Apricot C++ 4 04-16-2004 07:55 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57