Why can we virtual destructors but can't have virtual constructors? I have searched like anything. I got confused a lot after reading few articles on web. Please explain with some good example. Thanks in advance.
nitin1
15
Master Poster
Recommended Answers
Jump to PostWhy would you have a virtual constructor? The reason you use
virtual
is to create a virtual table so that when a function is called from a pointer to a base it will call the function of the derived object that was stored in that pointer. Since you have to …
Jump to Post@serpi90 I think you are confusing how derived objects get created. If you have:
class A { A() { /*do super complicated stuff in here to set up A*/ } virtual void Foo(); }; Class B : public A { B() : A() { /*set up the …
All 5 Replies
NathanOliver
429
Veteran Poster
Featured Poster
helmi_1
0
Newbie Poster
serpi90
0
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
serpi90
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.