Possible Duplicate:
Can you write object oriented code in C?
I’m wondering if it’s possible to use strict ANSI C as a object oriented language. And if it’s possible, how do I make a class in ANSI C. Allthough the language isn’t designed for OO, I’m really eager to try this.
Any examples, links etc. are appreciated.
A struct can hold methods and variables such that
struct myStructFoo{ int fooBar(); int privFooBar; };That is how you derive an OO “thing” using a plain old ANSI C compiler, if you want to learn the full OOP with C++ you will fare better with an ANSI C++ compiler as that is a better fit for your needs…as the OOP style using a C language is…. look at it this way, sure you can use a object using a struct, but the name is not exactly…intuitive…as a
structis more for holding fields and is part of integral data structures such as linked list, stacks, queues etc. If you had an ANSI C++ Compiler, this is how it would look:class myFoo{ public: int fooBar(); private: int privFooBar; };Compare and see how it appears more intuitive, information hiding is specified via the
publicandprivatekeywords.