atul jawale


{ City } pune
< Country > india
* Profession * senior technical leader
User No # 4009
Total Questions Posted # 0
Total Answers Posted # 3

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 118
Users Marked my Answers as Wrong # 14
Questions / { atul jawale }
Questions Answers Category Views Company eMail




Answers / { atul jawale }

Question { Siemens, 22614 }

What is a virtual base class?


Answer

Virtual base class is a base class acts as an indirect base
for more than one without duplication of its data members.

A single copy of its data members is shared by all the base
classes that use it as a virtual base.

For example:
A
/ \
B C
\ /
D

class A { /* ... */ }; // indirect base class
class B : virtual public A { /* ... */ };
class C : virtual public A { /* ... */ };
class D : public B, public C { /* ... */ }; // valid

Using the keyword virtual in this example ensures that an
object of class D inherits only one subobject of class A.

Is This Answer Correct ?    75 Yes 7 No

Question { NSN, 25419 }

What is the disadvantage of templates ?


Answer

Disadvantages of templates:

1. Many compilers historically have very poor support for
templates, so the use of templates can make code somewhat
less portable.
2. Almost all compilers produce confusing, unhelpful error
messages when errors are detected in template code. This
can make templates difficult to develop.
3. Each use of a template may cause the compiler to
generate extra code (an instantiation of the template), so
the indiscriminate use of templates can lead to code bloat,
resulting in excessively large executables.

Is This Answer Correct ?    40 Yes 7 No


Question { Wipro, 10984 }

In what cases using of a 'template' is a better approach
then using of a 'base class'?


Answer

Template is a better approach than using of a base class if:
1. Multiple copies of code for different data types with
the same logic.
2. If a set of functions or classes have the same
functionality for different data types
Then, a class becomes good candidates for being written as
Templates.

One good area where this C++ Class Templates are suited
can be container classes. Very famous examples for these
container classes will be the STL classes like vector, list
etc., Once code is written as a C++ class template, it can
support all data types.

Though very useful, It is advisable to write a class as a
template after getting a good hands-on experience on the
logic.

Is This Answer Correct ?    3 Yes 0 No