Define virtual function?, C/C++ Programming

Define virtual function?

Posted Date: 3/15/2013 6:20:12 AM | Location : United States





A: While derived class overrides the base class method through redefining the same function, then if client wished to access redefined the method from derived class via a pointer from base class object, then you have to described this function in base class as virtual function.

class parent                       

{

void Show()

{

cout << "i''m parent" << endl;

}

};

class child: public parent

{

void Show()

{

cout << "i''m child" << endl;

}

};

parent * parent_object_ptr = new child; parent_object_ptr->show() // calls parent->show() now we goto virtual world...

class parent

{

virtual void Show()

{

cout << "i''m parent" << endl;

}

};

class child: public parent

{

void Show()

{

cout << "i''m child" << endl;

}

};

parent * parent_object_ptr = new child;

parent_object_ptr->show() // calls child->show()

 

Posted by | Posted Date: 3/15/2013 6:20:39 AM

A: While derived class overrides the base class method through redefining the same function, then if client wished to access redefined the method from derived class via a pointer from base class object, then you have to described this function in base class as virtual function.

class parent                       

{

void Show()

{

cout << "i''m parent" << endl;

}

};

class child: public parent

{

void Show()

{

cout << "i''m child" << endl;

}

};

parent * parent_object_ptr = new child; parent_object_ptr->show() // calls parent->show() now we goto virtual world...

class parent

{

virtual void Show()

{

cout << "i''m parent" << endl;

}

};

class child: public parent

{

void Show()

{

cout << "i''m child" << endl;

}

};

parent * parent_object_ptr = new child;

parent_object_ptr->show() // calls child->show()

 

Posted by | Posted Date: 3/15/2013 6:29:13 AM

A: While derived class overrides the base class method through redefining the same function, then if client wished to access redefined the method from derived class via a pointer from base class object, then you have to described this function in base class as virtual function.

class parent                       

{

void Show()

{

cout << "i''m parent" << endl;

}

};

class child: public parent

{

void Show()

{

cout << "i''m child" << endl;

}

};

parent * parent_object_ptr = new child; parent_object_ptr->show() // calls parent->show() now we goto virtual world...

class parent

{

virtual void Show()

{

cout << "i''m parent" << endl;

}

};

class child: public parent

{

void Show()

{

cout << "i''m child" << endl;

}

};

parent * parent_object_ptr = new child;

parent_object_ptr->show() // calls child->show()

 

Posted by | Posted Date: 3/15/2013 6:29:27 AM


Related Discussions:- Define virtual function?, Assignment Help, Ask Question on Define virtual function?, Get Answer, Expert's Help, Define virtual function? Discussions

Write discussion on Define virtual function?
Your posts are moderated
Related Questions
Q: How can Define an Array? An Array is defined in much the alike manner as ordinary variables except that every array name must be accompanied by a size specification (that is

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw

In the Byteland country a string "s" is said to super ascii string if and only if count of each charecter in the string is equal to its ascci value in the byteland country ascii co

What are the various types of control structures in programming? - Primarily there are 3 types of control structures in programming: Sequence, Selection and Repetition. - Se

Explain Operators in C Language? The C language is very rich in built - in - operators and it places more significance on operators than do most other computer languages. The C

how to write c++ code for financial system using class and object

I am seeking an expert to create a 360 degree virtual tour in KRPano for use on PCs, tablets and smartphones. You will be given with panoramas in order to create an advanced KRPano

Templates permit to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until

A palindrome is a string that reads the same from the both the ends. Given a string S convert it to a palindrome by doing character replacement. Your takes is to convert S to palin

Project Description: Online game development Online Live Baccarat Game is needed - client program. - server program(IOCP or ect..). - web program(ASP or PHP or etc..