IT Community - Software Programming, Web Development and Technical Support

What are Virtual Functions? How to implement virtual functions in "C"?

This is a discussion on What are Virtual Functions? How to implement virtual functions in "C"? within the C and C++ Programming forums, part of the Software Development category; What are Virtual Functions? How to implement virtual functions in "C"?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-23-2007, 01:36 AM
Sabari Sabari is offline
D-Web Genius
 
Join Date: Jul 2007
Posts: 1,008
Sabari is on a distinguished road
Lightbulb What are Virtual Functions? How to implement virtual functions in "C"?

What are Virtual Functions? How to implement virtual functions in "C"?
__________________
Thanks & Regards
Sabari...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-31-2007, 01:32 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Arrow Re: What are Virtual Functions? How to implement virtual functions in "C"?

keep function pointers in function and use those function ptrs to perform the operation
__________________
The KINGMAKER
Makes Every Thing Possible

Stuffs (My Blog)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-10-2007, 11:30 PM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Sep 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Default Re: What are Virtual Functions? How to implement virtual functions in "C"?

hi all,
Virtual function:The virtual function is a member function of class which overrides the functionality in a derived classThe virtual function concept is not in a c which is in C++
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-10-2007, 11:33 PM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Sep 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Default Re: What are Virtual Functions? How to implement virtual functions in "C"?

C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes.

Virtual fundtions can be implemented using the keyword 'virtual' in the funtion declaration.

The property of virtual functions in C can be achieved by using function pointers or pointers to function
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-10-2007, 11:35 PM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default Re: What are Virtual Functions? How to implement virtual functions in "C"?

Code:
#include <stdio.h>


/* Though this code doesn't reflect exact C++ polymorphism(dynamic),
 i.e. same interface but different inplementation. Tried with different name
*/
void base(int dummy){
  printf("Recieving dummy from base - %d n", dummy);
}

void derive(int dummy){
  printf("Recieving dummy from der - %d n", dummy);
}

int main() {

 int dummy = 100;
 void (*funptr)(int);
 char ch;

 scanf("%c", &ch);
 
 /* Switch case to store the two interfaces address according to the input */
 switch (ch){
 case 'b':
  funptr=&base;
  break;
 case 'd':
  funptr=&derive;
  break;
 }

 /* Function pointer, which, is now, pointing to the function either "base" or "der". */
 
 funptr(dummy);

    return 0;
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explain the need for "Virtual Destructor". Sabari C and C++ Programming 1 07-31-2007 12:18 AM
I keep getting "Data Missing" when I click the "back" button in my browser. How can I oxygen HTML, CSS and Javascript Coding Techniques 1 07-28-2007 01:12 AM
Diffrence between a "assignment operator" and a "copy constructor" Sabari C and C++ Programming 1 07-24-2007 05:00 AM
Why do I get "HTTP 500" error(or "(DLL)initialization routine failed")in my browser? kingmaker ASP and ASP.NET Programming 1 07-20-2007 04:38 AM
Difference between a "assignment operator" and a "copy constructor"? vigneshgets C and C++ Programming 2 07-12-2007 05:30 AM


All times are GMT -7. The time now is 08:49 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0