LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to write a object oriented c program? (https://www.linuxquestions.org/questions/programming-9/how-to-write-a-object-oriented-c-program-354168/)

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: http://www.google.se/search?hl=sv&q=...%B6kning&meta=

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.