-   Programming (
-   -   How to write a object oriented c program? (

ssg14j 08-17-2005 07:00 AM

How to write a object oriented c program?
How to write a object oreinted c program?

give me one example.....

Ephracis 08-17-2005 07:02 AM

There are ways to program OO in C. This is called "Objective-C".

After a google search:

btmiller 08-17-2005 10:47 AM

AFAIK Objective-C is its own language, not really "C". Doing object oriented programming in C is very possible, for instance the Linux kernel uses OO techniques heavily. Just remember that C doesn't have language support for these features, so you have to roll your own objects, inheritence, polymorphism, etc. Inheritence is easily done via structs (structure slicing or having one struct as part of another) and polymorphism can be accomplished with lookup tables of function pointers (so one function dispatches to another based on the type of object it's called on). It's not the prettiest looking code in the world, but it works. I wrote a whole game back in ggrad school using these techniques (it was part of an assignment) and iot worked quite well. You can study the Linux kernel, particularly stuff like the VFS layer, to see an example of constructs like this in action.

All times are GMT -5. The time now is 12:03 PM.