Solved

A pure virtual function is a member function

Posted on 2011-03-17
5
465 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 74

Expert Comment

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

Expert Comment

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

Expert Comment

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

A, B and E.

-saige-

0
 
LVL 32

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

744 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

13 Experts available now in Live!

Get 1:1 Help Now