?
Solved

A pure virtual function is a member function

Posted on 2011-03-17
5
Medium Priority
?
493 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 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 44

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

777 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