Solved

A pure virtual function is a member function

Posted on 2011-03-17
5
486 Views
Last Modified: 2012-05-11
3. A pure virtual function is a member function (more than one)
a)      Whose declaration ends with = 0.
b)      That is used in a derived class only.
c)      That is used in a base class
d)      Takes no arguments
e)      Member form that is used to force all derived classes to implement that member function or be a pure virtual function member of the derived class.


I have selected A and D, but I am not sure if is also C
0
Comment
Question by:villmund
[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
  • 2
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35161262
IMO, B & E.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35161282
Nevermind. I'm way off  : )
0
 
LVL 34

Expert Comment

by:it_saige
ID: 35161304
I would have to say (since this is C++):

A, B and E.

-saige-

0
 
LVL 34

Accepted Solution

by:
it_saige earned 250 total points
ID: 35161311
A pure virtual function or pure virtual method is a virtual function that is required to be implemented by a derived class that is not abstract. Classes containing pure virtual methods are termed "abstract;" they cannot be instantiated directly, and a subclass of an abstract class can only be instantiated directly if all inherited pure virtual methods have been implemented by that class or a parent class. Pure virtual methods typically have a declaration (signature) and no definition (implementation).

As an example, an abstract base class "MathSymbol" may provide a pure virtual function doOperation(), and derived classes "Plus" and "Minus" implement doOperation() to provide concrete implementations. Implementing doOperation() would not make sense in the "MathSymbol" class as "MathSymbol" is an abstract concept whose behaviour is defined solely for each given kind (subclass) of "MathSymbol". Similarly, a given subclass of "MathSymbol" would not be complete without an implementation of doOperation().

Although pure virtual methods typically have no implementation in the class that declares them, pure virtual methods in C++ are permitted to contain an implementation in their declaring class, providing fallback or default behaviour that a derived class can delegate to if appropriate.

Pure virtual functions are also used where the method declarations are being used to define an interface for which derived classes will supply all implementations. An abstract class serving as an interface contains only pure virtual functions, and no data members or ordinary methods. Use of purely abstract classes as interfaces works in C++ as it supports multiple inheritance. Because many OO languages do not support multiple inheritance they often provide a separate interface mechanism. This is seen in Java for example.

[edit] C++In C++, pure virtual functions are declared using a special syntax [ = 0 ] as demonstrated below.

As posted here:  http://en.wikipedia.org/wiki/Virtual_function

Shorter version: http://www.glenmccl.com/tip_033.htm

Ofcourse, I may be way off base as well.  Because it does look like it can be declared in a base class.

-saige-
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 250 total points
ID: 35165458
I'd say A and E

a)      Whose declaration ends with = 0.
b)      That is used in a derived class only.
c)      That is used in a base class
d)      Takes no arguments
e)      Member form that is used to force all derived classes to implement that member function or be a pure virtual function member of the derived class.


d - it can have arguements, so this is false
c - it could be used but not necessarily has to be used, so this is false
b - as it can be called in the base class then this is also false.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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
maxMirror challenge 10 201
Python multiple IF statements 4 112
word0 challenge 4 74
Python 3.5.2 32 virtualenv problems 3 100
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

737 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