Object-orientation in C

前端 未结 22 1707
孤城傲影
孤城傲影 2020-11-22 15:26

What would be a set of nifty preprocessor hacks (ANSI C89/ISO C90 compatible) which enable some kind of ugly (but usable) object-orientation in C?

I am familiar with

22条回答
  •  没有蜡笔的小新
    2020-11-22 16:30

    If you think of methods called on objects as static methods that pass an implicit 'this' into the function it can make thinking OO in C easier.

    For example:

    String s = "hi";
    System.out.println(s.length());
    

    becomes:

    string s = "hi";
    printf(length(s)); // pass in s, as an implicit this
    

    Or something like that.

提交回复
热议问题