473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2080
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lefevre | last post by:
Hello I recently had troubles with a class inheritance hierarchy. I solved it, but it didn't satisfied me. I found the solution using this forum :) Actualy i found the following message...
11
by: Stub | last post by:
Please answer my questions below - thanks! 1. Why "Derived constructor" is called but "Derived destructor" not in Case 1 since object B is new'ed from Derived class? 2. Why "Derived destructor"...
6
by: Thomas Matthews | last post by:
Hi, Is placing the keyword "virtual" in front of a constructor allowed as in the sample below? class TTable { virtual TTable(); }; My compiler, Borland Builder 5.2, has system libraries
3
by: ccs | last post by:
In Meyers' book he gave an example of "virtual copy constructor", which is quite different to an "ordinary" copy constructor by: 1. it returns a pointer to an object instead of a reference. 2. it...
22
by: Ruben Van Havermaet | last post by:
Hi, I have a problem using member functions in derived classes that override virtual member functions of base classes. The following pieces of (simplified) code don't work. Can anybody give...
16
by: plmanikandan | last post by:
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
4
by: Stefan Nikolaus | last post by:
Hello, I've run into problems with defining a template, which inherits from a base template and the usage of virtual methods in those. I want to initialize a member variable depending on which...
3
by: Klaas Vantournhout | last post by:
Hi, Recently I obtained a problem with virtual inheritance when implementing it in multiple files. To present the problem I have included at the bottom of this post the code of the 4 files. I...
1
by: Bart Simpson | last post by:
Can anyone explain the concept of "slicing" with respect to the "virtual constructor" idiom as explain at parashift ? From parashift: class Shape { public: virtual ~Shape() { } ...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.