Solved

C++ questions here......

Posted on 2000-04-08
4
214 Views
Last Modified: 2010-04-02
1)
Is default constructor provided only when no user defined constructor is defined in msvc?

2)Is there any difference in the way default constructor is provided by c++ in Turboc++ and MSVC?

3)what is  a virtual destructor used for?

4)Is runtime polymorphism implemented by use of having virtual functions
or by having a base class pointer that can point to any one if its subclasses?


Thanks sridhar
0
Comment
Question by:kesavan_sridhar
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2696426
>> Is default constructor provided only when
>> no user defined constructor is defined in msvc?
This has nothing to do with MSVC.  It is part of standard C++.  A class will have an auto-generated default constructor, if:
a) you have not written any constructors for the class
b) all of its base classes have default constructors
c) all of its non-static data members have default constructors.

If these conditions are not met, the class will not have a default constructor generated by compiler.   You can still write a defautl constructor for the class, if desired.

continues
0
 
LVL 22

Expert Comment

by:nietod
ID: 2696433
>> is there any difference in the way default constructor
>> is provided by c++ in Turboc++ and MSVC?
I don'rt know what you mean by "provided".  But the default constructor may be implimented differently on different compilers, but that should not matter to you.  However the default constructor will have (or should have) the same behavior on all compilers.  However, turbo C++ is long long out-of-date, so there may be cases where it does not behave as prescribed by the standard.  Although you are not likely to find those sorts of problems in the default constructor, but I guess it is possible.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2696444
>> what is  a virtual destructor used for?
Like any other destructor, it is used to "clean-up" an object that it being destoyed.  It may be used to free resources used by the object, or don other class-specific clean-up tasks.

By making a destructor virtual you are assured that the destructor for a derived calss will be called correctly when an object of a derived class type is destroyed using a reference to one of its base classes.  i.e. if you delete using a pointer to an object that is typed as a base class pointer, but the object might be of a derived class, the destructor should be made virtual so that the right destructor is found and used at run time.  Otherwise, only the base class destructor will always be called, even if the object is a derived class object.

>> 4)Is runtime polymorphism implemented by use
>> of having virtual functions or by having a base
>> class pointer that can point to any one if its subclasses?
Both.
0
 

Author Comment

by:kesavan_sridhar
ID: 2714486
Thanks nietod for your answers....

bye sridhar
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
getting a fire fox page (view page source ) in c++ 6 45
Socket Programming (Unix) 8 153
Least Squares Curve Fitting 4 114
C++ help/ Toy problem 19 49
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question