Solved

C++ questions here......

Posted on 2000-04-08
4
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

627 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