Spicing C with classes

前端 未结 3 1062
挽巷
挽巷 2021-02-14 22:35

Disclaimer: I am a complete newbie with C, but I\'ve been playing with it trying to mimic some features of classes. Ok, I know that if I want to go that way I should lea

相关标签:
3条回答
  • 2021-02-14 23:14

    A book (in PDF form) that explains how to do it, is object oriented programming in ANSI C It's old (1993) but still contains some valid ideas and tips, IMHO.

    0 讨论(0)
  • 2021-02-14 23:15

    Various frameworks already exists. See for instance http://ldeniau.web.cern.ch/ldeniau/html/oopc.html

    0 讨论(0)
  • 2021-02-14 23:23

    Did you have a look at Google's Go? It's basically a modernized C where things are done somewhat in the way you suggested. It has parameter polymorphisms. So you don't have to do this:

    static void printFoo(struct foo self) {
        printf("This is bar: %d\n", self.bar);
    }
    

    In Go it can be done this way:

    static void print(Foo self) {
        printf("This is foo: %d\n", self.foo);
    }
    
    static void print(Bar self) {
        printf("This is bar: %d\n", self.bar);
    }
    

    In Go Foo and Bar would also be structs. So you are basically on the samet track as the Go language designers.

    For an overview of Go see http://golang.org/doc/effective_go.html This is the Go main language description: http://golang.org/doc/effective_go.html

    0 讨论(0)
提交回复
热议问题