Solved

C++ Queries

Posted on 2004-04-20
3
208 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
[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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 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