Converting a C++ class to a C struct (and beyond)

前端 未结 4 711
借酒劲吻你
借酒劲吻你 2020-12-16 08:04

Past few days I have been \"downgrading\" > 1000 filem of C++ code into C. It\'s been going well until now. Suddenly I\'m face to face with a class...

The compiler

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 08:32

    Turn foobar into a normal struct

    struct foobar {
        goo mutex;
    };
    

    Create your own "constructor" and "destructor" as functions that you call on that struct

    void InitFoobar(foobar* foo)
    {
       oneCreate(&foo->mutex);
    }
    
    void FreeFoobar(foobar* foo)
    {
       oneDestroy(foo->mutex);
    }
    
    struct foobar fooStruct;
    InitFoobar(&fooStruct);
    // ..
    FreeFoobar(&fooStruct);
    

    etc

提交回复
热议问题