Solved

C++ Queries

Posted on 2004-04-20
3
201 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
Comment Utility
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_
Comment Utility
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
Comment Utility
Homework
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

743 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

17 Experts available now in Live!

Get 1:1 Help Now