473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Virtual Function

Ritchie
wap using virtual function.

also wap using pointers.
Nov 15 '06 #1
6 2073
Banfa
9,065 Expert Mod 8TB
What do you mean by WAP?
Nov 15 '06 #2
What do you mean by WAP?
simple , it stands for write a program.

can u help me out asap,i mean as soon as possible
Nov 15 '06 #3
Banfa
9,065 Expert Mod 8TB
simple , it stands for write a program.
well normally it stands for Wireless APplication

Do you know what a virtual function is? Do you know what pointers are?

What would you like you program to do?
Nov 15 '06 #4
well normally it stands for Wireless APplication

Do you know what a virtual function is? Do you know what pointers are?

What would you like you program to do?
yes sir,
i very well know wat pointers nd virtual functions are,but d thing is i havent touched c++ for over 2 yrs. now.so,i'm starting it all over again.
Nov 15 '06 #5
Velhari
46
yes sir,
i very well know wat pointers nd virtual functions are,but d thing is i havent touched c++ for over 2 yrs. now.so,i'm starting it all over again.
Hi,
Virtual Function is simple one.... we used similar method names in base class and subclass means, we propose to use virtual function(Run-time Polymorphism)......

So, c++ determines which function to use at runtime based on the Object pointed by the Base Pointer rather than type of Pointer.

Here is a simple program for you to understand the concept of Virtual function

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2.  
  3. class virtual_example
  4. {
  5.       virtual void show()
  6.       {
  7.             cout<<"Base Class";
  8.       }
  9. }
  10. class sub extends virtual_example
  11. {
  12.      void show()
  13.      {
  14.           cout<<"Derived Class";
  15.      }
  16. }
  17. void main()
  18. {
  19.          virtual_example *v; //Base Pointer
  20.          virtual_example start;
  21.          sub end;
  22.  
  23.          v=&start;
  24.          v->show();
  25.  
  26.          v=&end;
  27.          v->show();
  28. }
With Regards,
Velmurugan.H
Nov 15 '06 #6
Hi,
Virtual Function is simple one.... we used similar method names in base class and subclass means, we propose to use virtual function(Run-time Polymorphism)......

So, c++ determines which function to use at runtime based on the Object pointed by the Base Pointer rather than type of Pointer.

Here is a simple program for you to understand the concept of Virtual function

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2.  
  3. class virtual_example
  4. {
  5.       virtual void show()
  6.       {
  7.             cout<<"Base Class";
  8.       }
  9. }
  10. class sub extends virtual_example
  11. {
  12.      void show()
  13.      {
  14.           cout<<"Derived Class";
  15.      }
  16. }
  17. void main()
  18. {
  19.          virtual_example *v; //Base Pointer
  20.          virtual_example start;
  21.          sub end;
  22.  
  23.          v=&start;
  24.          v->show();
  25.  
  26.          v=&end;
  27.          v->show();
  28. }
With Regards,
Velmurugan.H

thnx a lot.
Nov 16 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Roy Yao | last post by:
Hello, I need to pass a pointer to a callback function to the lower level modules. But the function is thought to be a virtual member one. How can I get the real address of the virtual...
23
by: heted7 | last post by:
Hi, Most of the books on C++ say something like this: "A virtual destructor should be defined if the class contains at least one virtual member function." My question is: why is it only for...
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
8
by: Floogle | last post by:
how do i create a virtual == operator. I've tried the following but it's incorrect... class Interface { ... public: virtual bool operator==(const Interface& rhs)const=0;
6
by: pakis | last post by:
I am having a problem of pure virtual function call in my project. Can anyone explaine me the causes of pure virtual function calls other than calling a virtual function in base class? Thanks
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
7
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see...
10
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a...
7
by: desktop | last post by:
This page: http://www.eptacom.net/pubblicazioni/pub_eng/mdisp.html start with the line: "Virtual functions allow polymorphism on a single argument". What does that exactly mean? I guess it...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.