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
Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Described the differences among a C++ struct & C++ class? A: The default member & base class access specifies are distinct. It is one of the commonly misunderstood aspects of C+

Function Templates Function templates give you with the capability to write a one function that is a skeleton, or template, for a family of similar functions. In function ov

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

A: this is a procedure during exception handling while the destructor is called for all local objects in the stack among the place where the exception was thrown & where this is ca

Need Payment Gateway Integration Expert Project Description: I am seeking for expert payment gateway integration. You must have done or have experience with integrating me

Hello I''m new to programming, and I''m making now my 1st program. My question is how to put substr in textbox that question mark should be at the end of sentence? And 2nd question

#questionAt a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Write a Haskell program that calculates a balanced partition of N items where each item has a value between 0 and K such that the difference between the sum of the values of first