Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Virtual constructor

Reply
Thread Tools

Virtual constructor

 
 
plmanikandan@gmail.com
Guest
Posts: n/a
 
      03-14-2006
Hi,
I have doubts reg virtual constructor
what is virtual constructor?
Is c++ supports virtual constructor?
Can anybody explain me about virtual constructor?


Regards,
Mani

 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      03-14-2006
plmanikandan wrote:

> Can anybody explain me about virtual constructor?


Raw C++ cannot call a constructor virtually (because a constructor is not
really a function). There's probably some common design pattern.

How about you use Google to survey the topic and report back here?

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!


 
Reply With Quote
 
 
 
 
al pacino
Guest
Posts: n/a
 
      03-14-2006
hii,
there is no such thing as virtual constructor in c++, it doesn't make
sense.
a constructor IS a function(can be defined explicitly , compiler calls
it when an object of a
class is CREATED.)

A virtual destructor is required to resolve the ambiguity,when a
derived class object
is deleted via a base class pointer(a 'derived class' IS A 'base
class') since compiler
has to decide what to delete derived object or base object.
thus declareing the destructor virtual resolves the ambugity.

concept of virtual constructor doesnt' make sense to me.
please correct me if nething is out of place here.
thanks

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-14-2006
* http://www.velocityreviews.com/forums/(E-Mail Removed):
>
> I have doubts reg virtual constructor


Note: "doubt" means you are unsure whether something is true or not, or
whether a person is truthful or reliable, or not.

Your usage above is meaningless and probably due to a bad dictionary.


> what is virtual constructor?


See the FAQ. Use the FAQ's Google search (it's on the main page of the
FAQ) to find the phrase "virtual constructor" in the FAQ. Apart from
that meaning, which has only a peripheral connection to the words
"virtual" and "constructor" (it's more like a random phrase that for
some historical reason has acquired a given meaning), the FAQ also
discusses another more natural meaning; search the FAQ for the phrase
"Dynamic Binding During Initialization" to find that discussion.


> Is c++ supports virtual constructor?


Yes.


> Can anybody explain me about virtual constructor?


Yes, see the FAQ.

Hth.,

- Alf

--
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?
 
Reply With Quote
 
Sunil Varma
Guest
Posts: n/a
 
      03-14-2006

(E-Mail Removed) wrote:
> Hi,
> I have doubts reg virtual constructor
> what is virtual constructor?
> Is c++ supports virtual constructor?
> Can anybody explain me about virtual constructor?
>
>
> Regards,
> Mani


When you make a function virtual that function is binded after the
object has been created.
But if you take a constructor it is called at the time of creation of
the object.
Constructor cannot be binded after the object is created.

 
Reply With Quote
 
al pacino
Guest
Posts: n/a
 
      03-14-2006
dude how can the constructors can be virtual ??
here is the reference frm bjarne stroustrup's tech. faq:
http://public.research.att.com/~bs/b...l#virtual-ctor

Alf P. Steinbach wrote:
> * (E-Mail Removed):
> >
> > I have doubts reg virtual constructor

>
> Note: "doubt" means you are unsure whether something is true or not, or
> whether a person is truthful or reliable, or not.
>
> Your usage above is meaningless and probably due to a bad dictionary.
>
>
> > what is virtual constructor?

>
> See the FAQ. Use the FAQ's Google search (it's on the main page of the
> FAQ) to find the phrase "virtual constructor" in the FAQ. Apart from
> that meaning, which has only a peripheral connection to the words
> "virtual" and "constructor" (it's more like a random phrase that for
> some historical reason has acquired a given meaning), the FAQ also
> discusses another more natural meaning; search the FAQ for the phrase
> "Dynamic Binding During Initialization" to find that discussion.
>
>
> > Is c++ supports virtual constructor?

>
> Yes.
>
>
> > Can anybody explain me about virtual constructor?

>
> Yes, see the FAQ.
>
> Hth.,
>
> - Alf
>
> --
> 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?


 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-14-2006
* al pacino:
> [top-posting]
> [quoting extranous material]
> [quoting signature]


Please don't top-post. Please don't quote irrelevant stuff. See the
FAQ and Shiva's monthly "Welcome"-posting in this group.

--
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?
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      03-14-2006
al pacino wrote:

> dude how can the constructors can be virtual ??


Easy. What is commonly called a "virtual constructor" just happens not to be
a constructor (like the Holy Roman Empire was neither roman nor holy and it
is debatable whether it was an empire).

> here is the reference frm bjarne stroustrup's tech. faq:
> http://public.research.att.com/~bs/b...l#virtual-ctor


Did you read what he wrote there? I quote from *that* page:

Techniques for using an indirection when you ask to create an object
are often referred to as "Virtual constructors". For example, see
TC++PL3 15.6.2.

> Alf P. Steinbach wrote:
>> * (E-Mail Removed):

[snip]

And please, don't top-post.


Best

Kai-Uwe Bux
 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      03-14-2006
"Alf P. Steinbach" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>* (E-Mail Removed):
>>
>> I have doubts reg virtual constructor

>
> Note: "doubt" means you are unsure whether something is true or not, or
> whether a person is truthful or reliable, or not.
>
> Your usage above is meaningless and probably due to a bad dictionary.


Actually, it's probably because he's Norweigian and English is not his
primary language.

>> what is virtual constructor?

>
> See the FAQ. Use the FAQ's Google search (it's on the main page of the
> FAQ) to find the phrase "virtual constructor" in the FAQ. Apart from that
> meaning, which has only a peripheral connection to the words "virtual" and
> "constructor" (it's more like a random phrase that for some historical
> reason has acquired a given meaning), the FAQ also discusses another more
> natural meaning; search the FAQ for the phrase "Dynamic Binding During
> Initialization" to find that discussion.
>
>> Is c++ supports virtual constructor?

>
> Yes.


No. From the FAQ 20.8 in part:

An idiom that allows you to do something that C++ doesn't directly support.

>> Can anybody explain me about virtual constructor?

>
> Yes, see the FAQ.


Yes, see the FAQ 20.8 You can't have a virtual constructor, but you can
have something that mimics what a virtual constructor would do.

Again, FAQ 20.8 in a bigger part:
You can get the effect of a virtual constructor by a virtual clone() member
function (for copy constructing), or a virtual create() member function (for
the default constructor).

Here is the link to the FAQ 20.8:
http://www.parashift.com/c++-faq-lit....html#faq-20.8


 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      03-14-2006
* Jim Langston:
> "Alf P. Steinbach" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> * (E-Mail Removed):
>>> I have doubts reg virtual constructor

>> Note: "doubt" means you are unsure whether something is true or not, or
>> whether a person is truthful or reliable, or not.
>>
>> Your usage above is meaningless and probably due to a bad dictionary.

>
> Actually, it's probably because he's Norweigian and English is not his
> primary language.
>
>>> what is virtual constructor?

>> See the FAQ. Use the FAQ's Google search (it's on the main page of the
>> FAQ) to find the phrase "virtual constructor" in the FAQ. Apart from that
>> meaning, which has only a peripheral connection to the words "virtual" and
>> "constructor" (it's more like a random phrase that for some historical
>> reason has acquired a given meaning), the FAQ also discusses another more
>> natural meaning; search the FAQ for the phrase "Dynamic Binding During
>> Initialization" to find that discussion.
>>
>>> Is c++ supports virtual constructor?

>> Yes.

>
> No. From the FAQ 20.8 in part:
>
> An idiom that allows you to do something that C++ doesn't directly support.
>
>>> Can anybody explain me about virtual constructor?

>> Yes, see the FAQ.

>
> Yes, see the FAQ 20.8 You can't have a virtual constructor, but you can
> have something that mimics what a virtual constructor would do.
>
> Again, FAQ 20.8 in a bigger part:
> You can get the effect of a virtual constructor by a virtual clone() member
> function (for copy constructing), or a virtual create() member function (for
> the default constructor).
>
> Here is the link to the FAQ 20.8:
> http://www.parashift.com/c++-faq-lit....html#faq-20.8


I'm not sure what point (if any) you were trying to make? Confuse the
newbie, and remove his or her learning experience in searching the FAQ?
Look how smart I am, I managed to find it in the FAQ?

Anyway, your unqualified "no" above is incorrect. C++ does indeed
support all that's needed to implement what's known as a virtual
constructor, including virtual member functions and function result
covariance. Note that this does not contradict the FAQ's statement.

Hth.,

- Alf

--
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?
 
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
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
Copy constructor hides default constructor Aire C++ 3 01-25-2004 05:47 PM
java like constructor calling constructor lallous C++ 5 01-23-2004 11:52 PM
calling a constructor within a constructor Brett Irving C++ 3 06-29-2003 10:43 AM
why it's not possible calling constructor from constructor? Giulio C++ 9 06-25-2003 03:56 PM



Advertisments