Spicing C with classes

前端 未结 3 1061
挽巷
挽巷 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: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

提交回复
热议问题