Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++ questions here......

Posted on 2000-04-08
4
Medium Priority
?
232 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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

916 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