Default constructor in C

后端 未结 13 672
孤街浪徒
孤街浪徒 2020-12-07 21:02

Is there a way to have some kind of default constructor (like a C++ one) for C user types defined with a structure?

I already have a macro which works like a fast in

13条回答
  •  既然无缘
    2020-12-07 21:29

    You might want to take a look at a C++ compiler. It gives you more object oriented features than you can remember in a language having a C-like syntax in a more elegant and standard way than trying to bolt constructors and so forth onto C with libraries and macros.

    If that doesn't work for you then take a look at GObject. http://en.wikipedia.org/wiki/GObject. It is an object system for C used in GTK and Gnome that pretty much cranks "objects in C" to 11.

    From Wikipedia:

    The GLib Object System, or GObject, is a free software library (covered by the LGPL) that provides a portable object system and transparent cross-language interoperability.

    The system supports constructors, destructors, single inheritance, interfaces, virtual public and private methods and so forth. It's also much more tedious and difficult than doing the same things in C++. Have fun!

提交回复
热议问题