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
Solved

C++ Queries

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 114
ASP.net build a IF/Then Walkthrough Guide 1 233
No module found pypyodbc, 3 32
Are the two lines the same? If not what is the difference? 2 22
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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…

839 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