Solved

C++ Queries

Posted on 2004-04-20
3
202 Views
Last Modified: 2006-11-17
Q1)If Base class is to be abstract but none of the virtual member functon can be reasonably required to be pure then which of the following is the best choice to make a pure virtual function and why?
Default Constructer,Copy Constructer,Destructor,Assignment operator


Q2)Is this works Derived** to Base**
a)It will work ,b)Run time error c)Compiler error

I want the answers of the above questions, Moreover Can u please tell me from where I can find
these type of programming brain teasers

Sebnak
0
Comment
Question by:sebnak
3 Comments
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 20 total points
ID: 10867912
Q1: Default Constructer,Copy Constructer,Destructor,Assignment operator

None of them can be made pure virtual. Constructors never are virtual (because there is no instance where virtuality could work on), destructor may be virtual but not pure virtual (as all destructors get called) and operators can not be virtual.

Q2: Compile error. However, that compiles:

    Derived   d;
    Derived*  pd = &d;
    Derived** ppd = &pd;
    Base*     pb  = pd;
    Base**    ppb = &pb;


>> these type of programming brain teasers

Don't know what you mean exactly?

Regards, Alex


0
 
LVL 2

Expert Comment

by:sin_
ID: 10876996
1. For your 1st question, use the virtual destructor.

Though you make it pure, you still need to provide the body for it. Otherwise, it will give you a linking problem.

2.  You gotta use the dynamic_cast for it.

Hope this helps
0
 
LVL 7

Expert Comment

by:jj819430
ID: 10878283
Homework
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

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 video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

920 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

14 Experts available now in Live!

Get 1:1 Help Now