-1

Possible Duplicate:
Can you write object oriented code in C?

Does C support simple class without polymorphism, inheritance etc.?

I need only definition of class and methods.

Community
  • 1
  • 1
VisionAir
  • 45
  • 1

3 Answers3

6

C has no class concept on its own.

It is possible, however, to implement something like that:

struct stuff {
    void (*do_it)(void);
    void (*close)(void);
};

struct stuff new(void) {
    struct stuff ret;
    ret.do_it = ...;
    ret.close = ...;
    return ret;
}


int main() {
    struct stuff s = new();
    s.do_it();
    s.close();
}
glglgl
  • 89,107
  • 13
  • 149
  • 217
5

You can use a struct and store function-pointers in it.

Bernd Elkemann
  • 23,242
  • 4
  • 37
  • 66
  • It isn't very simple: I have to generate C code from another language (by Xtend) and without classes it is very difficult to emulate some construct of other language. – VisionAir Dec 07 '12 at 14:44
2

C is not object oriented. So no. But it supports structs

xlecoustillier
  • 16,183
  • 14
  • 60
  • 85