Solved

C++ questions here......

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 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 how to clear a vector as well as how to detect empty vectors in C++.

746 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

10 Experts available now in Live!

Get 1:1 Help Now