Solved

C++ questions here......

Posted on 2000-04-08
4
186 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now