471,075 Members | 1,045 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

virtual constructor

can u explain me the concept of virtual constructor. Does such concept
exists in c++

Jul 22 '05 #1
6 1947
"uday" <ka***********@yahoo.co.in> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
can u explain me the concept of virtual constructor. Does such concept
exists in c++


http://www.parashift.com/c++-faq-lit....html#faq-20.6

DW

Jul 22 '05 #2
uday wrote:
can u explain me the concept of virtual constructor. Does such concept
exists in c++

Check this:

http://www.research.att.com/~bs/bs_f...l#virtual-ctor

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 22 '05 #3

"David White" <no@email.provided> wrote in message
news:1f******************@nasal.pacific.net.au...
"uday" <ka***********@yahoo.co.in> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
can u explain me the concept of virtual constructor. Does such concept
exists in c++


http://www.parashift.com/c++-faq-lit....html#faq-20.6


I'm having trouble understanding this line from that FAQ:

"This function will work correctly regardless of whether the Shape is a
Circle, Square, or some other kind-of Shape that doesn't even exist yet."

What do they mean by "some other kind-of Shape that doesn't even exist
yet."? Are they talking about a forward declared class? And what does
clone() and create() return if the subtype doesn't exist?
Jul 22 '05 #4
* Method Man:

"David White" <no@email.provided> wrote in message
news:1f******************@nasal.pacific.net.au...
"uday" <ka***********@yahoo.co.in> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
can u explain me the concept of virtual constructor. Does such concept
exists in c++


http://www.parashift.com/c++-faq-lit....html#faq-20.6


I'm having trouble understanding this line from that FAQ:

"This function will work correctly regardless of whether the Shape is a
Circle, Square, or some other kind-of Shape that doesn't even exist yet."


The above means that the code calling the virtual constructor does not
need to know the particular kind of Shape. A compiled version of such
code, X, can be linked to other code so that it will be creating a kind
of Shape that didn't exist when X was compiled. The new kind of Shape
is introduced after compilation, but before linking, of X.

By the way, I should mention that the term "virtual constructor" has
another common meaning, namely that of a constructor that can be fully
or partially overridden in a derived class. I think this is the more
natural meaning. However, the first meaning (20.6) was introduced first
in the FAQ, and so the second needed a new term, "Dynamic Binding During
Initialization", or DBDI, which Marshall invented when we introduced a
discussion of techniques for the second meaning in the FAQ.

You find that discussion at <url:
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.4>.

--
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?
Jul 22 '05 #5
Method Man wrote:


I'm having trouble understanding this line from that FAQ:

"This function will work correctly regardless of whether the Shape is a
Circle, Square, or some other kind-of Shape that doesn't even exist yet."

What do they mean by "some other kind-of Shape that doesn't even exist
yet."? Are they talking about a forward declared class?
Alf has already answered that part
And what does
clone() and create() return if the subtype doesn't exist?


That situation is not possible.
If you think of it, clone() or create() are always applied on an already
existing object. So you *must* already have an object of that type in
order to call clone() or create() on it.
You can think of it this way: The clone() call in

Shape* TheShape = Get_A_Shape_Object_From_Somwehere();
Shape* AnotherShape = TheShape->clone();

can be translated in ordinary english:
Hey object where TheShape points to! I have no idea what you really
are and I don't care. But please create a new object which is a copy
of yourself.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #6

"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
* Method Man:

"David White" <no@email.provided> wrote in message
news:1f******************@nasal.pacific.net.au...
"uday" <ka***********@yahoo.co.in> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
> can u explain me the concept of virtual constructor. Does such concept > exists in c++
>

http://www.parashift.com/c++-faq-lit....html#faq-20.6

I'm having trouble understanding this line from that FAQ:

"This function will work correctly regardless of whether the Shape is a
Circle, Square, or some other kind-of Shape that doesn't even exist

yet."
The above means that the code calling the virtual constructor does not
need to know the particular kind of Shape. A compiled version of such
code, X, can be linked to other code so that it will be creating a kind
of Shape that didn't exist when X was compiled. The new kind of Shape
is introduced after compilation, but before linking, of X.


Thanks, the wording had me confused.
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Lefevre | last post: by
11 posts views Thread by Stub | last post: by
6 posts views Thread by Thomas Matthews | last post: by
3 posts views Thread by ccs | last post: by
22 posts views Thread by Ruben Van Havermaet | last post: by
16 posts views Thread by plmanikandan | last post: by
4 posts views Thread by Stefan Nikolaus | last post: by
3 posts views Thread by Klaas Vantournhout | last post: by
1 post views Thread by Bart Simpson | last post: by
reply views Thread by leo001 | last post: by

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.