GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  
 C++  |  Question 203 of 203    Print  
Invoke the virtual toString() function
To invoke the virtual toString() function defined in GeometricObject from a Circle object c, use :
A. ((GeometricObject*)c)->toString();
B. c.super.toString()
C. (GeometricObject*)c->toString();
D. c->GeometricObject::toString()



  
Total Answers and Comments: 3 Last Update: November 15, 2009     Asked by: dlee6565 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 02, 2009 11:02:46   #1  
Parvath Member Since: August 2009   Contribution: 1    

RE: Invoke the virtual toString() function

D. c->GeometricObject::toString()


 
Is this answer useful? Yes | No
November 01, 2009 09:06:56   #2  
MercurySystemsEngineering Member Since: November 2009   Contribution: 1    

RE: Invoke the virtual toString() function
When using polymorphic functions(virtual) in order to access the BASE class version of the function from WITHIN the Derived class one would simply say "Base::functionName()".

For e.g:

class CGeometricObject
{
public:
virtual void toString()
{
// do something..
}
};

class CCircle : public CGeometricObject
{
public:
void toString()
{
CGeometricObject::toString(); // call BASE class version of toString (first)
}
}

 
Is this answer useful? Yes | No
November 14, 2009 16:59:05   #3  
tawofala Member Since: November 2009   Contribution: 2    

RE: Invoke the virtual toString() function
A. ((GeometricObject*)c)->toString();
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape