?
Solved

A pure virtual function is a member function

Posted on 2011-03-17
5
Medium Priority
?
528 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
  • 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 35

Expert Comment

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

A, B and E.

-saige-

0
 
LVL 35

Accepted Solution

by:
it_saige earned 1000 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 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to implement Singleton Design Pattern in Java.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

840 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