Solved

A pure virtual function is a member function

Posted on 2011-03-17
5
466 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 33

Expert Comment

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

A, B and E.

-saige-

0
 
LVL 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 68
NotAlone Challenge 20 79
groovy example issue 10 90
Problem to open Excel file 15 97
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

910 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

25 Experts available now in Live!

Get 1:1 Help Now