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 struct
is 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 public
and private
keywords.