GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-May-2006, 23:52
Janakiraman Janakiraman is offline
Junior Member
 
Join Date: Apr 2005
Location: Chennai - India
Posts: 47
Janakiraman is on a distinguished road

Help in Virtual function


Hi All,

I am familiar with virtual functions but i am not able to identify under which circumstances virtual functions should be used.

So does anybody provide a two type of source code, one without using virtual functions and another with using virtual functions of same functionalaties?

This will help to understand under which circumstances virtual functions can be applied.

Best Regards,
Janakiraman
  #2  
Old 31-May-2006, 00:15
aie0 aie0 is offline
Member
 
Join Date: Dec 2004
Posts: 246
aie0 is a jewel in the roughaie0 is a jewel in the rough

Re: Help in Virtual function


CPP / C++ / C Code:
class base
{
virtual void do() { out<<"1";}
};

class derive: public base
{
virtual void do() { out<<"2"; }
};

void main()
{
base* obj = new derive();
obj->do();
}
-----------
output: 2

Without using virtual function the output will be 1
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What does =0 in Pure virtual function means? Poolan CPP / C++ Forum 4 26-May-2006 14:58
pure virtual function vatsa_mitr CPP / C++ Forum 1 12-May-2006 00:41
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
[Tutorial] Function Pointers aaroncohn CPP / C++ Forum 4 17-Feb-2006 11:33
Revising Script style ?????? pepee MySQL / PHP Forum 4 14-Apr-2004 04:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:14.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.